mirror of https://github.com/AxioDL/metaforce.git
Replaced blowfish with xxhash
This commit is contained in:
parent
d924e0b6cd
commit
5309dcd56b
|
@ -141,7 +141,7 @@ void BlenderConnection::_closePipe()
|
|||
close(m_writepipe[1]);
|
||||
}
|
||||
|
||||
BlenderConnection::BlenderConnection(bool silenceBlender)
|
||||
BlenderConnection::BlenderConnection(int verbosityLevel)
|
||||
{
|
||||
BlenderLog.report(LogVisor::Info, "Establishing BlenderConnection...");
|
||||
|
||||
|
@ -206,8 +206,9 @@ BlenderConnection::BlenderConnection(bool silenceBlender)
|
|||
}
|
||||
|
||||
wchar_t cmdLine[2048];
|
||||
_snwprintf(cmdLine, 2048, L" --background -P \"%s\" -- %" PRIuPTR " %" PRIuPTR " \"%s\"",
|
||||
blenderShellPath.c_str(), uintptr_t(writehandle), uintptr_t(readhandle), blenderAddonPath.c_str());
|
||||
_snwprintf(cmdLine, 2048, L" --background -P \"%s\" -- %" PRIuPTR " %" PRIuPTR " %d \"%s\"",
|
||||
blenderShellPath.c_str(), uintptr_t(writehandle), uintptr_t(readhandle),
|
||||
verbosityLevel > 1 ? 1 : 0, blenderAddonPath.c_str());
|
||||
|
||||
STARTUPINFO sinfo = {sizeof(STARTUPINFO)};
|
||||
HANDLE nulHandle = NULL;
|
||||
|
@ -242,7 +243,7 @@ BlenderConnection::BlenderConnection(bool silenceBlender)
|
|||
close(m_writepipe[1]);
|
||||
close(m_readpipe[0]);
|
||||
|
||||
if (silenceBlender)
|
||||
if (verbosityLevel == 0)
|
||||
{
|
||||
int devNull = open("/dev/null", O_WRONLY);
|
||||
dup2(devNull, STDOUT_FILENO);
|
||||
|
@ -254,13 +255,15 @@ BlenderConnection::BlenderConnection(bool silenceBlender)
|
|||
snprintf(readfds, 32, "%d", m_writepipe[0]);
|
||||
char writefds[32];
|
||||
snprintf(writefds, 32, "%d", m_readpipe[1]);
|
||||
char dverbose[32];
|
||||
snprintf(dverbose, 32, "%d", verbosityLevel > 1 ? 1 : 0);
|
||||
|
||||
/* Try user-specified blender first */
|
||||
if (blenderBin)
|
||||
{
|
||||
execlp(blenderBin, blenderBin,
|
||||
"--background", "-P", blenderShellPath.c_str(),
|
||||
"--", readfds, writefds, blenderAddonPath.c_str(), NULL);
|
||||
"--", readfds, writefds, dverbose, blenderAddonPath.c_str(), NULL);
|
||||
if (errno != ENOENT)
|
||||
{
|
||||
snprintf(errbuf, 256, "NOLAUNCH %s\n", strerror(errno));
|
||||
|
@ -272,7 +275,7 @@ BlenderConnection::BlenderConnection(bool silenceBlender)
|
|||
/* Otherwise default blender */
|
||||
execlp(DEFAULT_BLENDER_BIN, DEFAULT_BLENDER_BIN,
|
||||
"--background", "-P", blenderShellPath.c_str(),
|
||||
"--", readfds, writefds, blenderAddonPath.c_str(), NULL);
|
||||
"--", readfds, writefds, dverbose, blenderAddonPath.c_str(), NULL);
|
||||
if (errno != ENOENT)
|
||||
{
|
||||
snprintf(errbuf, 256, "NOLAUNCH %s\n", strerror(errno));
|
||||
|
|
|
@ -41,7 +41,7 @@ class BlenderConnection
|
|||
size_t _writeBuf(const char* buf, size_t len);
|
||||
void _closePipe();
|
||||
public:
|
||||
BlenderConnection(bool silenceBlender=false);
|
||||
BlenderConnection(int verbosityLevel=1);
|
||||
~BlenderConnection();
|
||||
|
||||
bool createBlend(const SystemString& path);
|
||||
|
@ -229,7 +229,7 @@ public:
|
|||
static inline BlenderConnection& SharedConnection()
|
||||
{
|
||||
if (!SharedBlenderConnection)
|
||||
SharedBlenderConnection = new BlenderConnection(HECL::VerbosityLevel?false:true);
|
||||
SharedBlenderConnection = new BlenderConnection(HECL::VerbosityLevel);
|
||||
return *SharedBlenderConnection;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ if '--' not in sys.argv:
|
|||
args = sys.argv[sys.argv.index('--')+1:]
|
||||
readfd = int(args[0])
|
||||
writefd = int(args[1])
|
||||
double_verbose = int(args[2])
|
||||
if sys.platform == "win32":
|
||||
import msvcrt
|
||||
readfd = msvcrt.open_osfhandle(readfd, os.O_RDONLY | os.O_BINARY)
|
||||
|
@ -35,8 +36,8 @@ def quitblender():
|
|||
|
||||
# If there's a third argument, use it as the .zip path containing the addon
|
||||
did_install = False
|
||||
if len(args) >= 3 and args[2] != 'SKIPINSTALL':
|
||||
bpy.ops.wm.addon_install(overwrite=True, target='DEFAULT', filepath=args[2])
|
||||
if len(args) >= 4 and args[3] != 'SKIPINSTALL':
|
||||
bpy.ops.wm.addon_install(overwrite=True, target='DEFAULT', filepath=args[3])
|
||||
bpy.ops.wm.addon_refresh()
|
||||
did_install = True
|
||||
|
||||
|
@ -76,7 +77,8 @@ def count_brackets(linestr):
|
|||
|
||||
# Complete sequences of statements compiled/executed here
|
||||
def exec_compbuf(compbuf, globals):
|
||||
#print('EXEC', compbuf)
|
||||
if double_verbose:
|
||||
print('EXEC', compbuf)
|
||||
co = compile(compbuf, '<HECL>', 'exec')
|
||||
exec(co, globals)
|
||||
|
||||
|
|
|
@ -27,4 +27,4 @@ endif()
|
|||
target_link_libraries(hecl
|
||||
${DATA_SPEC_LIBS}
|
||||
HECLDatabase HECLBlender HECLCommon AthenaCore NOD
|
||||
LogVisor AthenaLibYaml ${PNG_LIB} squish blowfish ${ZLIB_LIBRARIES} ${LZO_LIB} ${PLAT_LIBS})
|
||||
LogVisor AthenaLibYaml ${PNG_LIB} squish xxhash ${ZLIB_LIBRARIES} ${LZO_LIB} ${PLAT_LIBS})
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
add_subdirectory(libSquish)
|
||||
add_subdirectory(blowfish)
|
||||
add_subdirectory(xxhash)
|
||||
add_subdirectory(LogVisor)
|
||||
add_subdirectory(Athena)
|
||||
add_subdirectory(libpng)
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
add_library(blowfish blowfish.c blowfish.dat.c blowfish.h)
|
|
@ -1,128 +0,0 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include "blowfish.h"
|
||||
|
||||
#define N 16
|
||||
|
||||
extern const uint32_t BLOWFISH_P[N + 2];
|
||||
extern const uint32_t BLOWFISH_S[4][256];
|
||||
|
||||
#define P BLOWFISH_P
|
||||
#define S BLOWFISH_S
|
||||
|
||||
static uint32_t F(uint32_t x)
|
||||
{
|
||||
uint16_t a;
|
||||
uint16_t b;
|
||||
uint16_t c;
|
||||
uint16_t d;
|
||||
uint32_t y;
|
||||
|
||||
d = x & 0x00FF;
|
||||
x >>= 8;
|
||||
c = x & 0x00FF;
|
||||
x >>= 8;
|
||||
b = x & 0x00FF;
|
||||
x >>= 8;
|
||||
a = x & 0x00FF;
|
||||
y = S[0][a] + S[1][b];
|
||||
y = y ^ S[2][c];
|
||||
y = y + S[3][d];
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
void Blowfish_encipher(uint32_t *xl, uint32_t *xr)
|
||||
{
|
||||
uint32_t Xl;
|
||||
uint32_t Xr;
|
||||
uint32_t temp;
|
||||
short i;
|
||||
|
||||
Xl = *xl;
|
||||
Xr = *xr;
|
||||
|
||||
for (i = 0; i < N; ++i) {
|
||||
Xl = Xl ^ P[i];
|
||||
Xr = F(Xl) ^ Xr;
|
||||
|
||||
temp = Xl;
|
||||
Xl = Xr;
|
||||
Xr = temp;
|
||||
}
|
||||
|
||||
temp = Xl;
|
||||
Xl = Xr;
|
||||
Xr = temp;
|
||||
|
||||
Xr = Xr ^ P[N];
|
||||
Xl = Xl ^ P[N + 1];
|
||||
|
||||
*xl = Xl;
|
||||
*xr = Xr;
|
||||
}
|
||||
|
||||
void Blowfish_decipher(uint32_t *xl, uint32_t *xr)
|
||||
{
|
||||
uint32_t Xl;
|
||||
uint32_t Xr;
|
||||
uint32_t temp;
|
||||
short i;
|
||||
|
||||
Xl = *xl;
|
||||
Xr = *xr;
|
||||
|
||||
for (i = N + 1; i > 1; --i) {
|
||||
Xl = Xl ^ P[i];
|
||||
Xr = F(Xl) ^ Xr;
|
||||
|
||||
/* Exchange Xl and Xr */
|
||||
temp = Xl;
|
||||
Xl = Xr;
|
||||
Xr = temp;
|
||||
}
|
||||
|
||||
/* Exchange Xl and Xr */
|
||||
temp = Xl;
|
||||
Xl = Xr;
|
||||
Xr = temp;
|
||||
|
||||
Xr = Xr ^ P[1];
|
||||
Xl = Xl ^ P[0];
|
||||
|
||||
*xl = Xl;
|
||||
*xr = Xr;
|
||||
}
|
||||
|
||||
int64_t Blowfish_hash(const uint8_t* buf, size_t len)
|
||||
{
|
||||
unsigned i,j;
|
||||
union
|
||||
{
|
||||
uint32_t h32[2];
|
||||
int64_t h64;
|
||||
} hash = {0,0};
|
||||
|
||||
for (i=0 ; i<len/4 ; ++i)
|
||||
{
|
||||
uint32_t block = *(uint32_t*)buf;
|
||||
Blowfish_encipher(&hash.h32[i&1], &block);
|
||||
buf += 4;
|
||||
}
|
||||
|
||||
unsigned rem = len % 4;
|
||||
if (rem)
|
||||
{
|
||||
union
|
||||
{
|
||||
uint32_t b32;
|
||||
char b[4];
|
||||
} block = {0};
|
||||
for (j=0 ; j<rem ; ++j)
|
||||
block.b[j] = *(char*)buf;
|
||||
Blowfish_encipher(&hash.h32[i&1], &block.b32);
|
||||
}
|
||||
|
||||
return hash.h64;
|
||||
}
|
||||
|
Binary file not shown.
|
@ -1,265 +0,0 @@
|
|||
const unsigned long BLOWFISH_P[] = {
|
||||
0xECE2997A,0x878D9BB6,0xBD99A37F,0x87CE5082,
|
||||
0x731DA749,0x8D1593C4,0x7759157C,0x64B420F3,
|
||||
0x16FE203E,0x8D5D0E1A,0x9F8BFD16,0xE50AAE06,
|
||||
0x6F69D85E,0x4A2B2E2C,0x6C6092F3,0x3E6E839C,
|
||||
0x7332BC74,0xEB9C5558,
|
||||
};
|
||||
const unsigned long BLOWFISH_S[] = {
|
||||
0x421D7293,0x2EC59345,0x9EACE875,0x4B558191,
|
||||
0xD37BEE4C,0x5D9A8E3C,0x21102E6F,0x478600F2,
|
||||
0xFCC4FA37,0x78D81A66,0xC1D6A5A6,0x5CF4D077,
|
||||
0x5B001183,0x6C6BF222,0xA1E6B437,0x25258DFC,
|
||||
0xB0B6A5C9,0xB922A022,0x6F599F11,0x33AC5389,
|
||||
0x0BD2CE8A,0xD2BF3D3B,0xEDB1971C,0xABFA231C,
|
||||
0x250CC0B4,0x1D8F3A1D,0x9CC9C373,0x470F5F5D,
|
||||
0xF1B26237,0x7CCECDEB,0xB2652840,0xC43C5DC7,
|
||||
0x52AB9291,0x3CA0F779,0x93C120E2,0x9657FE6C,
|
||||
0x18E28A36,0x38CBD5C3,0x91321972,0x143C8019,
|
||||
0x9A986345,0x089BC863,0x088D97D9,0x9AA5298F,
|
||||
0xBDB4C22E,0xFDDB607B,0x09F6200E,0xF4762B60,
|
||||
0x112068A4,0xC9C34AAA,0x1646AE14,0x3ED8ABC3,
|
||||
0x812F9820,0xBE8166F2,0x11992911,0x7E73D832,
|
||||
0xFFEEEB21,0x2914E308,0x52762303,0x3A1AAF59,
|
||||
0x6D684400,0x68CEEA3F,0x8020E74C,0x23932FD1,
|
||||
0x7F81C903,0x28D1DF23,0x47C6546F,0x10E9906D,
|
||||
0x2FC7E523,0x788B31B6,0xA34779FE,0xD4D3CBCB,
|
||||
0xA2669C45,0x160EE34B,0xEEC86439,0x01A68E02,
|
||||
0xC19122FA,0x47108632,0x5ED39396,0x3ACE13D8,
|
||||
0x1F6DA64C,0x8BDF89A4,0x0340FB9E,0x139DBCFF,
|
||||
0x5F975A6E,0x0BC71EE0,0x4BCD423F,0xD17F8EBD,
|
||||
0x9C32844C,0x231E2B4F,0x32764ECA,0x31A86FEB,
|
||||
0x510786F3,0xC3AD90C6,0x723A86FE,0x5B473CF0,
|
||||
0x0F1D8D3D,0xD53B2CD6,0x3EB4E682,0xB7F499B6,
|
||||
0x364C0FA9,0x8C6DFE24,0xEFDD8593,0x5A8C8FD9,
|
||||
0xFB09F4FF,0x755D8664,0x18172338,0xA730DF83,
|
||||
0x6D5CAF4D,0xE1AF6FC8,0x52A3A7C5,0xE92640C0,
|
||||
0x1D26389F,0xE6F81F9F,0x30EE4466,0xA9A2B2FD,
|
||||
0xDE5E9F8B,0x820D01C4,0x801A3EBF,0x868D144F,
|
||||
0xE19FD5CC,0xED5982B9,0x40788FA3,0x9D5D0603,
|
||||
0x2EBB28DA,0x6440756F,0x462528A1,0x180987F2,
|
||||
0xDCD71AC1,0x8322365A,0x3567ECAF,0x9C1AB502,
|
||||
0x3AFCB4C0,0x2D316F8D,0xF838B706,0x83D6167A,
|
||||
0xA8CA2242,0x92251B43,0xFB475A07,0xD6B84FF6,
|
||||
0xE6E545FF,0xED984921,0xE85F1731,0xAB95905C,
|
||||
0x139A180D,0xBDF6B63E,0x2E49C8D0,0x91E936B4,
|
||||
0xA5CD4333,0x6E4420B3,0x99846D33,0xBB6A36F2,
|
||||
0xBCC62D7E,0x83B9C684,0x4F1D67C9,0x6EEA5BE4,
|
||||
0xA5C1FBA9,0xD5903D0A,0x3A7D01A3,0xCEF6B09E,
|
||||
0x8A9038DD,0x6CC5D354,0xFC8E6BE9,0xC31EB29C,
|
||||
0xF6EB895D,0xBC5CC652,0x108FC0ED,0xBC4BD7C6,
|
||||
0xF5B247DA,0xC8B6DC25,0xA9AC3ABE,0x2472E65C,
|
||||
0x20C3DB8B,0xC3C2874F,0x86C09F29,0x3138F070,
|
||||
0x971005D9,0xC81A7769,0x16D7B065,0xD66B2E55,
|
||||
0xB85D5B2C,0xA3D31A82,0xB3EEA578,0xA813810E,
|
||||
0x070D1377,0xD445453D,0xC71D5128,0xC6BE1578,
|
||||
0xF08F6428,0xBB6A896D,0xC89AF5BE,0xC917210B,
|
||||
0x7285DFC4,0x68B5EA23,0x3EA24BC8,0x83F2EFA1,
|
||||
0x3C4F6B8C,0x709EF994,0x04468F7E,0x07F1E3E2,
|
||||
0xA4B6C9A8,0xECF2B777,0xD9583CA8,0x992DA6B4,
|
||||
0xCDB55EE2,0x7BCB7842,0xE7E9B318,0x43893D4A,
|
||||
0xFF8CC771,0xB9C65E4D,0xCCD233D1,0x5B394220,
|
||||
0x11655394,0xD093D599,0xD54CBED0,0xC39214C9,
|
||||
0x49BC9528,0xCD176E1D,0x953E5364,0x0245FBAC,
|
||||
0xA4CB8CD4,0x44DA688D,0xBEE0F8FD,0x34906411,
|
||||
0x29205E3A,0xBBF92030,0xDFEDC07A,0xF66F3C07,
|
||||
0x78FFC26D,0x7005FE9A,0x3BF5FE65,0x34CA0E22,
|
||||
0x51E859F8,0x73866086,0x025BA522,0xE1BF5A23,
|
||||
0xE9FBF06F,0x78630F0F,0x49D87ED6,0x1E4E522E,
|
||||
0xD7DAA554,0x73F897DA,0x7E837E88,0x19C4F285,
|
||||
0xEF5DCED2,0xBF4CBE2C,0x6B3C44ED,0x35197A88,
|
||||
0xC3021855,0x278FD11F,0x55854B29,0xA71A1A1D,
|
||||
0xFA3CBA9E,0x71A8DED1,0x04286C0D,0x51A31113,
|
||||
0xBF38301F,0x6A105725,0xE0FC3F53,0x79FC8C6F,
|
||||
0x0A8E94EB,0xF9598BE7,0xB53147A5,0x1867499F,
|
||||
0x77680751,0xDE9854A7,0x4E5B491C,0x8076EE6D,
|
||||
0xF800F274,0x3E027A2B,0x618E1D68,0x95E7D26A,
|
||||
0xE88DF5DA,0xDCA65187,0x706D9C25,0x3D32FFA6,
|
||||
0x26154F23,0x481661AC,0x1C9E7501,0x2668D7CA,
|
||||
0x29AE367B,0xAB1BCAB4,0x5956746C,0x408FB623,
|
||||
0x70FDA74D,0x267A3C22,0xCE245B56,0x6D46CBC5,
|
||||
0x3E9A1DBF,0xF4B14956,0x6433C3E9,0x2512F370,
|
||||
0x710A1269,0x45D25252,0x8F0E0035,0xE93E893F,
|
||||
0x059F0EF9,0xBAACE2BA,0x0442C220,0x4315F1FC,
|
||||
0xB46B7BC8,0xA9E5978D,0xB887DFE3,0x934F68B0,
|
||||
0xF5A3AD6D,0xFAF2A641,0x62E319A8,0xAA7BA0FC,
|
||||
0x97933E9F,0x905BA2A2,0x22698B3E,0x7C403613,
|
||||
0x48B91B6C,0x76D589C3,0xEA0AF0D9,0x254541E4,
|
||||
0x4C68FCA3,0x861A5BBD,0x0C3D2814,0x11410597,
|
||||
0x39B93083,0x9856F056,0xF9D62D99,0xBB857A8A,
|
||||
0xDCDE7FEE,0x854B8A34,0x11941383,0xE7A00321,
|
||||
0x59414DEF,0x4AD7291D,0x892FA9CA,0x08E8F54B,
|
||||
0x8DC5620A,0x2057BAC5,0xEF7A58AC,0x07A149C4,
|
||||
0xBA8F3C45,0x1D96D12B,0x9C66B748,0x95C5B4B7,
|
||||
0xED541CC2,0xA251536D,0xA4EDBB76,0x38604523,
|
||||
0x635E92E9,0xE5A2F89E,0x5B525EAD,0x5CA050C9,
|
||||
0x3C87A7A9,0x89070858,0x37152C1A,0xBAA2FE68,
|
||||
0x27033C24,0x50C19D69,0x965E070C,0x611C561F,
|
||||
0x4FB28DD1,0xEFFD2B22,0xC9FCD75C,0x82192997,
|
||||
0x0420F5A7,0x04B11929,0xF60465E3,0x988CCC21,
|
||||
0x8B2BA5A1,0x70421CF6,0x8D3A12B2,0x5A9245A6,
|
||||
0xC7F6141A,0xD7C28FF6,0xE8669164,0x60AD7642,
|
||||
0x918FB28A,0x7E44CA1E,0xA42DF8EE,0x06FD9F89,
|
||||
0x3EC461C1,0x588BB24A,0xD770532B,0xD3A71097,
|
||||
0x1BB81AFE,0xC824B481,0x488393DA,0x73C1E3AF,
|
||||
0x24B1C15E,0x48AAC468,0xBD55BEF3,0x9FC11E9D,
|
||||
0xEF2CE2FF,0xBD633C50,0x6FDE4D94,0x2C31F2F6,
|
||||
0x6EDD1BC0,0x43B3D5CB,0x21A9DE5A,0x3193CC6A,
|
||||
0x16604CA5,0x2A3C5050,0x32BAFA40,0x082E56AF,
|
||||
0x8A085A4D,0x4B278229,0xE2693335,0x4B94B79A,
|
||||
0xF1CF9999,0xF5674594,0x13FFC8AE,0x0FA8089D,
|
||||
0x77A8DADD,0x10352C72,0x84AD2262,0x3E9687B2,
|
||||
0x0F644F40,0xF84EB9FC,0x70F83CEC,0xC0014469,
|
||||
0x88BD4381,0x8697108F,0xC93D7C3A,0x7C328F90,
|
||||
0xBD14A599,0x435D6435,0xE73B4D63,0x80BCA793,
|
||||
0x1A08E670,0x173D780F,0x38890082,0xF728D66C,
|
||||
0x78AD5448,0x5848FAEF,0x28766E24,0x25B37D9B,
|
||||
0xDD7B5711,0x3061587B,0x7D7F9C69,0x26CDC35C,
|
||||
0x186E5105,0x63F6BACF,0x785FC8E2,0xB3D56F12,
|
||||
0x9B5EE2AE,0x37831B5D,0x4C24053A,0x4AFB1ED4,
|
||||
0x19C8E276,0xAFAB7962,0xB5B6EFBB,0xA845B632,
|
||||
0xDD267596,0xAE653EF6,0xDCBE94B5,0x8D2F32BD,
|
||||
0x986F8F0D,0x6812F0C5,0x2FD16C8A,0xA178342B,
|
||||
0x28F6453B,0xBB389EF4,0xAE4FEF56,0xAD769918,
|
||||
0xA255A773,0x11448CA8,0xA455382B,0xB1ACCBA6,
|
||||
0xD40C2707,0x01022D06,0x1260150F,0x03549650,
|
||||
0x875FF827,0x8848FD7F,0x5724F044,0x72AADBAA,
|
||||
0xD22038BF,0x4C632982,0xC05D490A,0xAD7C22F9,
|
||||
0xB5D81AED,0x87B3DCC8,0x6CA81B06,0x379475FC,
|
||||
0x82F94B61,0x188E3FF8,0x3105EE03,0x4C81B5C0,
|
||||
0xBCA1FE23,0x288C904F,0x67CAB301,0xCD839435,
|
||||
0xEDBC05E4,0x89F9CDA7,0x042A93A2,0xA27CD38E,
|
||||
0x2D56C211,0xE7AD278D,0x1C7E1D41,0xE7F7B82A,
|
||||
0x83EF848B,0xB0343EF5,0xD86DE0CE,0x8C887D41,
|
||||
0x633F4E48,0xB61E3116,0x8D381492,0x64EE8715,
|
||||
0xE9593093,0x932F8560,0x29BBF110,0x849DDDA2,
|
||||
0x72E4084F,0xE0E2FC14,0xD449B863,0x28949AA5,
|
||||
0x6F3F93DE,0x5610FD4B,0x6626E7E8,0x7ED92BBC,
|
||||
0xE5C54C68,0x7A21C8B4,0xCE7DF6AA,0x4E7E6D4D,
|
||||
0xE0C71068,0x07A0D021,0xBD93F36C,0x4FA001AF,
|
||||
0x9DF25F75,0xB1EEAAC2,0x272A3BEA,0x90F35536,
|
||||
0x5D2DF0F5,0x61862870,0x3A72E272,0xDA5C0E3C,
|
||||
0x58BEAA84,0x0C5D82BD,0xEE7B3142,0x1A2C7CF7,
|
||||
0xE166D9E9,0x8D210F18,0x9AFA021F,0x8CA402C4,
|
||||
0x07D5AABC,0xEE604E42,0xA083A093,0xA8025CA2,
|
||||
0xFF529528,0x2021CC44,0x858A6FFE,0x390E00AD,
|
||||
0x95F91CAB,0x94E28A82,0x015144A7,0x847B894A,
|
||||
0xB1459D0C,0x90EC6130,0xB193FCA7,0x5CF05C19,
|
||||
0xABE438AF,0x8633254E,0xDA173369,0x9929619F,
|
||||
0x43B1F909,0xEE249E40,0xC977654B,0x5CEEDE29,
|
||||
0x376AFD4E,0xA156EA63,0x2C52E11B,0x6321370A,
|
||||
0x5C37C873,0xD8B97243,0x5E306568,0x67AB98C7,
|
||||
0xF92A3D45,0x9CE53640,0xBFC0F799,0x780E7221,
|
||||
0x30240C05,0x53D4FC61,0x6F4F00A5,0x7019DCCE,
|
||||
0xD210665D,0xD4DE43BF,0xA0C4906D,0x9A959121,
|
||||
0x6B3C9A6E,0xDA6CA139,0xF0EC6479,0x1239DFE7,
|
||||
0xF849A1E1,0x642DD95D,0xF97F5545,0x9535790A,
|
||||
0x26226531,0xA38E6F02,0x093AD3A5,0x020955BB,
|
||||
0x7148D565,0xF63E8167,0xA55502C8,0x941EACF2,
|
||||
0xA23D89FF,0x7BE7C397,0x963BAD54,0x07D31203,
|
||||
0xA8C5CFD6,0x88998563,0x7070518A,0x0ADDE3B9,
|
||||
0x3CEEB1CF,0xA85CB4C1,0xEF6CE433,0xDE30E959,
|
||||
0x5767C0EC,0x6A410015,0x93AECAC8,0xE7D933B5,
|
||||
0x0BC4D71B,0xE52FA620,0xE5AC4224,0xEE189ED8,
|
||||
0x25370151,0x641D64B8,0x57EB26B0,0xCC035118,
|
||||
0xCE3AB51F,0xE74B4A3F,0x56400FCB,0xDA240998,
|
||||
0x795BBE06,0x0FE37753,0x58A8F106,0x0C4550EA,
|
||||
0xAC660A0C,0xC0360865,0x0F5A373F,0xFB77C558,
|
||||
0xABA1BE8C,0x3A60CB0F,0x5B4660CB,0xE2DCD316,
|
||||
0x7EDF11A4,0x8FB55220,0xFC3E3EA9,0x79A91FA3,
|
||||
0x72BA250C,0xF3F1FB10,0x06650DB7,0x4888875C,
|
||||
0x038B941D,0x0BC7CB8A,0xA558266A,0x8125270C,
|
||||
0xF9C6A655,0x97375314,0x3D5AC65E,0x7BF5B5FB,
|
||||
0x7DE1B472,0x8AD00491,0x23434745,0xF8C72F5A,
|
||||
0xA9E96818,0x877E8739,0xE129CE24,0x60016BDA,
|
||||
0xA589380F,0xE2A2136D,0xF28791E9,0x98023D6E,
|
||||
0x3F60A5B5,0xA2D81D0A,0x2B72C734,0xC2FED55D,
|
||||
0xBE72E7E4,0x75C4BE91,0x18000D47,0x44648EEE,
|
||||
0xBA5F98C3,0x8AFE6227,0x549FB360,0x0A5F91BC,
|
||||
0xB5FE7915,0x925145CC,0x60B52089,0x4F2775F9,
|
||||
0xF12E7521,0x5979EC96,0xB40C584C,0xD9079BFD,
|
||||
0x6E0087D3,0x75F304F3,0x4D8CF539,0xA9D5B761,
|
||||
0xC2B6C8AC,0xDB62C83F,0x478AD1F6,0x37F5D9E9,
|
||||
0x27312221,0x77D44C63,0xCDB8BC34,0x6DD03B96,
|
||||
0xFCA9A53E,0xF8748694,0x1DBB0972,0x3CF7831E,
|
||||
0x40B045D8,0xA7177F11,0x999409EE,0x737D5F7D,
|
||||
0xE7DD0A3E,0x5423FC7C,0x1947177E,0x2B1BD645,
|
||||
0xD81780D9,0x67ED703A,0x48E2E18E,0xC26EE041,
|
||||
0xDCE51290,0x1BC8E826,0x19BE2BBC,0xB5CB2246,
|
||||
0x33A54A14,0x3DEB0BDC,0xCD2FA6E2,0x5F1F261C,
|
||||
0xD95013C0,0x545F7DC8,0x11E3ECD4,0x48C36163,
|
||||
0x87417051,0x91CD5A84,0x4807B0AB,0x9C560515,
|
||||
0x33176BCD,0xA47CD74E,0x74C4CAE8,0xB988A1D9,
|
||||
0xE99E3134,0x6871F912,0x49918C65,0xAFA0FD31,
|
||||
0x5F62AB88,0x39375AE1,0x64665842,0x00AB4DFC,
|
||||
0x43F94B42,0xBDC0450F,0xD49520D0,0x6F215C70,
|
||||
0xF3EACBEA,0x6A0293B7,0x10ECE2FE,0x81BDFFC0,
|
||||
0x8DB5952A,0x19D8B352,0xFA341EB3,0x4038059D,
|
||||
0x8C351E18,0xB6E931C1,0xF2ED3ECA,0x384D0BD9,
|
||||
0xED004F2B,0x6F3A34B5,0x9F63CAEB,0xFC6ED801,
|
||||
0x67B611D7,0xB1729B09,0xF7F3FC13,0x3F45FC82,
|
||||
0x95B6F12B,0x798357F8,0xEC7005CF,0x9729BF68,
|
||||
0xFEB68AD6,0xE6214661,0xC79F2FC6,0x2A62FC00,
|
||||
0x952EE069,0xC324D73E,0xBB75D0B4,0x1B3C157A,
|
||||
0x138D6D37,0x7FD3535B,0x401F5BC4,0xFB6A17EE,
|
||||
0xDAA02563,0xC0D11734,0x4A14F41F,0xAFF1D9BD,
|
||||
0xD576BC77,0xE76E394D,0x999A7F72,0xB87637AC,
|
||||
0x4500E2FD,0x4DE46925,0x105B44BF,0xE7719951,
|
||||
0xB23F6608,0xDA09378B,0xE6785D14,0xB9D3D087,
|
||||
0x01E43279,0xE0E21827,0x61A78890,0x5430F676,
|
||||
0x3BEF316E,0xD5668DFC,0x5965785B,0x69756DE0,
|
||||
0x4D27188F,0x461A3E80,0xD0017994,0xD053E020,
|
||||
0x4C354799,0x743ACF50,0x512AC0D4,0xCB55EBFD,
|
||||
0x0884E3AE,0x3FA2346E,0x843E8966,0x38B8A818,
|
||||
0x82B70A21,0x140FB35D,0x2705F723,0x7D061F13,
|
||||
0x8CD668E6,0x657B5F87,0x8050CA9B,0x949857EE,
|
||||
0x2E79EA0F,0x4415B763,0xC289FEF4,0x41CE8F7A,
|
||||
0xDEE4FB69,0x38D698E1,0xEBCFAE8D,0xABB4B975,
|
||||
0xA6EFF066,0x19442C2B,0x823984F6,0xAD69E725,
|
||||
0x35B84874,0xBA7D95AC,0xE55CD936,0xA3B31928,
|
||||
0x1BC94FEA,0x1DB555A6,0x8D5685D6,0xE82FE735,
|
||||
0x05DD952A,0xEAD60A51,0xA8C23FD9,0x23E2F4B1,
|
||||
0x00BB7FCF,0x28D1785D,0xB9BA3917,0xE9309960,
|
||||
0x977DFE25,0xA27813A9,0xF77DDA48,0x92F1CDC9,
|
||||
0xB071A5A2,0xB72063B9,0x5ED69228,0xD7DFF757,
|
||||
0x9559F7E1,0xE10A8CD8,0xA3A2E8CE,0x37ACEC9A,
|
||||
0x327135A0,0xE2589B14,0x974450F0,0x5D20C609,
|
||||
0x84BEAD73,0x16DA4AA7,0x2A56C444,0x9383D8AE,
|
||||
0x87A85082,0xD6464389,0xD7F0E4FB,0x69E03B48,
|
||||
0x89FE2FBB,0xA3BB6B64,0xE2742F13,0x0CB318F5,
|
||||
0xA35B334E,0x9409122A,0x6A1AA74D,0xA66D37BD,
|
||||
0xFED04165,0x54AFC1D7,0xCAE9321A,0x6EBF1FCA,
|
||||
0xDBD82D9C,0xA6AF629A,0x020BE359,0xE489161E,
|
||||
0xE8D2E4CE,0xB8688AD8,0xB36D6260,0xE75B3F0D,
|
||||
0x3B1F2ED8,0x6A57437E,0x66AA1B5A,0x801F1985,
|
||||
0x12398344,0x1D76CB53,0x8B14271D,0x94EB5CD1,
|
||||
0x95BB6C11,0xAF29869F,0x8B0BD55F,0xDB4A96AC,
|
||||
0x5D76DBB8,0xB79B2BD2,0x1DE977D4,0x70C46079,
|
||||
0x158C4A11,0x2A27C18A,0x1279D53C,0x19B3494A,
|
||||
0x1D72B811,0xAA19F50D,0x83755185,0x07692F45,
|
||||
0xBC3C96DE,0x996C5C57,0x8D7FE502,0x9078A744,
|
||||
0x3F2E6EB8,0x47871BCC,0x745D634A,0xAAAC893E,
|
||||
0xF90A6979,0x33B84450,0xBB66F3E8,0xB1D3F872,
|
||||
0x5351A2E3,0x456026D2,0xBE493C68,0xEE1F2739,
|
||||
0x446A9AC8,0xA42D07B9,0x4C9D02A5,0x474E7675,
|
||||
0xA9A0C840,0x719E8295,0x7D2C9156,0xCEF602A5,
|
||||
0x0FBA9D12,0x37349207,0xC0F3C7C9,0xC513B94E,
|
||||
0x428067F3,0x6A73EC2A,0x1124068E,0x5C08C9B1,
|
||||
0x02A66533,0x9832196C,0x60317F5A,0x455A4886,
|
||||
0x9F7C495B,0x87BB6754,0xA686DA84,0x6E0DC2A1,
|
||||
0xB9548F8F,0xFE383139,0xCCFA6A55,0x15418A66,
|
||||
0x512918A4,0x60ED8CD0,0x0F556316,0xBBADA8D0,
|
||||
0xB1DB7D9F,0x2F0A9259,0x92FD3E34,0x636BC287,
|
||||
0x04C837D4,0xB30BB311,0x4AE4A9C8,0x6561A8C6,
|
||||
0xDE3E342B,0xB9DE12C4,0xA5AB0BF6,0x20A9FB0E,
|
||||
0xB669B1DD,0xCBFBBA85,0x264332EE,0x1CD28CC6,
|
||||
0x240CDDD3,0xBFBE7BA3,0x431A4A71,0xB55FC792,
|
||||
0x48E33646,0x4380FD82,0x9DF7FBBD,0xBC30DE31,
|
||||
0x3D950D25,0xA0775F51,0x8AE9F434,0xDCE3D490,
|
||||
0xF2EB87C3,0x0426BE6E,0xAAF40F97,0xD034EC8D,
|
||||
0x2AC4B781,0x1E382DE5,0xBB09F263,0x6100257E,
|
||||
0x82CCFE8A,0xF350DF77,0x86FA5CD4,0x2BF09255,
|
||||
0xEDD42D4D,0x812DEE18,0xCF47B5CF,0x8D059B5A,
|
||||
0x87BB31B3,0x6DFCA21B,0x69C60380,0x790FED88,
|
||||
0xAB68958B,0x9E3A1278,0x3A7A7D9D,0xD7FD6BF6,
|
||||
};
|
|
@ -1,14 +0,0 @@
|
|||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
void Blowfish_encipher(uint32_t *xl, uint32_t *xr);
|
||||
void Blowfish_decipher(uint32_t *xl, uint32_t *xr);
|
||||
int64_t Blowfish_hash(const uint8_t* buf, size_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -1,104 +0,0 @@
|
|||
import struct
|
||||
|
||||
P = []
|
||||
S = []
|
||||
|
||||
def F(x):
|
||||
d = x & 0x00FF
|
||||
x >>= 8
|
||||
c = x & 0x00FF
|
||||
x >>= 8
|
||||
b = x & 0x00FF
|
||||
x >>= 8
|
||||
a = x & 0x00FF
|
||||
#y = ((S[0][a] + S[1][b]) ^ S[2][c]) + S[3][d];
|
||||
y = S[0][a] + S[1][b]
|
||||
y = y ^ S[2][c]
|
||||
y = y + S[3][d]
|
||||
|
||||
return y
|
||||
|
||||
def bfencipher(xl, xr):
|
||||
Xl = xl
|
||||
Xr = xr
|
||||
|
||||
for i in range(16):
|
||||
Xl = Xl ^ P[i]
|
||||
Xr = F(Xl) ^ Xr
|
||||
|
||||
temp = Xl
|
||||
Xl = Xr
|
||||
Xr = temp
|
||||
|
||||
temp = Xl
|
||||
Xl = Xr
|
||||
Xr = temp
|
||||
|
||||
Xr = Xr ^ P[16]
|
||||
Xl = Xl ^ P[16+1]
|
||||
|
||||
return Xl&0xffffffff, Xr&0xffffffff
|
||||
|
||||
key = bytearray()
|
||||
with open('hecl_key', 'r') as keyin:
|
||||
b = keyin.read(2)
|
||||
while len(b):
|
||||
if len(b) != 2:
|
||||
break
|
||||
key += struct.pack('B', int(b, 16))
|
||||
b = keyin.read(2)
|
||||
|
||||
if len(key) < 8:
|
||||
raise RuntimeError('key must be at least 8 bytes in length')
|
||||
|
||||
with open('blowfish.dat', 'rb') as fin:
|
||||
word = fin.read(4)
|
||||
for i in range(18):
|
||||
P.append(struct.unpack(">I", word)[0])
|
||||
word = fin.read(4)
|
||||
for i in range(4):
|
||||
sub = []
|
||||
for j in range(256):
|
||||
sub.append(struct.unpack(">I", word)[0])
|
||||
word = fin.read(4)
|
||||
S.append(sub)
|
||||
|
||||
j = 0
|
||||
for i in range(18):
|
||||
data = 0x00000000
|
||||
for k in range(4):
|
||||
data = (data << 8) | key[j]
|
||||
j = j + 1
|
||||
if j >= len(key):
|
||||
j = 0
|
||||
P[i] = P[i] ^ data
|
||||
|
||||
datal = 0x00000000
|
||||
datar = 0x00000000
|
||||
|
||||
for i in range(9):
|
||||
datal, datar = bfencipher(datal, datar)
|
||||
P[i*2] = datal
|
||||
P[i*2+1] = datar
|
||||
|
||||
for i in range(4):
|
||||
for j in range(128):
|
||||
datal, datar = bfencipher(datal, datar)
|
||||
S[i][j*2] = datal
|
||||
S[i][j*2+1] = datar
|
||||
|
||||
with open('blowfish.dat.c', 'w') as fout:
|
||||
fout.write('const unsigned long BLOWFISH_P[] = {')
|
||||
for i in range(18):
|
||||
if not i%4:
|
||||
fout.write('\n ')
|
||||
fout.write('0x%08X,' % P[i])
|
||||
fout.write('\n};\n')
|
||||
fout.write('const unsigned long BLOWFISH_S[] = {')
|
||||
for i in range(4):
|
||||
for j in range(256):
|
||||
if not (i*256+j)%4:
|
||||
fout.write('\n ')
|
||||
fout.write('0x%08X,' % S[i][j])
|
||||
fout.write('\n};\n')
|
||||
|
|
@ -1 +0,0 @@
|
|||
CA75FA1170DABBAD00BADD00D5B00B51
|
|
@ -0,0 +1 @@
|
|||
add_library(xxhash xxhash.c xxhash.h)
|
|
@ -0,0 +1,24 @@
|
|||
xxHash Library
|
||||
Copyright (c) 2012-2014, Yann Collet
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@ -0,0 +1,962 @@
|
|||
/*
|
||||
xxHash - Fast Hash algorithm
|
||||
Copyright (C) 2012-2015, Yann Collet
|
||||
|
||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
You can contact the author at :
|
||||
- xxHash source repository : https://github.com/Cyan4973/xxHash
|
||||
*/
|
||||
|
||||
|
||||
/**************************************
|
||||
* Tuning parameters
|
||||
**************************************/
|
||||
/* XXH_FORCE_MEMORY_ACCESS
|
||||
* By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable.
|
||||
* Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal.
|
||||
* The below switch allow to select different access method for improved performance.
|
||||
* Method 0 (default) : use `memcpy()`. Safe and portable.
|
||||
* Method 1 : `__packed` statement. It depends on compiler extension (ie, not portable).
|
||||
* This method is safe if your compiler supports it, and *generally* as fast or faster than `memcpy`.
|
||||
* Method 2 : direct access. This method is portable but violate C standard.
|
||||
* It can generate buggy code on targets which generate assembly depending on alignment.
|
||||
* But in some circumstances, it's the only known way to get the most performance (ie GCC + ARMv6)
|
||||
* See http://stackoverflow.com/a/32095106/646947 for details.
|
||||
* Prefer these methods in priority order (0 > 1 > 2)
|
||||
*/
|
||||
#ifndef XXH_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
|
||||
# if defined(__GNUC__) && ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) )
|
||||
# define XXH_FORCE_MEMORY_ACCESS 2
|
||||
# elif defined(__INTEL_COMPILER) || \
|
||||
(defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) ))
|
||||
# define XXH_FORCE_MEMORY_ACCESS 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* XXH_ACCEPT_NULL_INPUT_POINTER :
|
||||
* If the input pointer is a null pointer, xxHash default behavior is to trigger a memory access error, since it is a bad pointer.
|
||||
* When this option is enabled, xxHash output for null input pointers will be the same as a null-length input.
|
||||
* By default, this option is disabled. To enable it, uncomment below define :
|
||||
*/
|
||||
/* #define XXH_ACCEPT_NULL_INPUT_POINTER 1 */
|
||||
|
||||
/* XXH_FORCE_NATIVE_FORMAT :
|
||||
* By default, xxHash library provides endian-independant Hash values, based on little-endian convention.
|
||||
* Results are therefore identical for little-endian and big-endian CPU.
|
||||
* This comes at a performance cost for big-endian CPU, since some swapping is required to emulate little-endian format.
|
||||
* Should endian-independance be of no importance for your application, you may set the #define below to 1,
|
||||
* to improve speed for Big-endian CPU.
|
||||
* This option has no impact on Little_Endian CPU.
|
||||
*/
|
||||
#define XXH_FORCE_NATIVE_FORMAT 0
|
||||
|
||||
/* XXH_USELESS_ALIGN_BRANCH :
|
||||
* This is a minor performance trick, only useful with lots of very small keys.
|
||||
* It means : don't make a test between aligned/unaligned, because performance will be the same.
|
||||
* It saves one initial branch per hash.
|
||||
*/
|
||||
#if defined(__i386) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64)
|
||||
# define XXH_USELESS_ALIGN_BRANCH 1
|
||||
#endif
|
||||
|
||||
|
||||
/**************************************
|
||||
* Compiler Specific Options
|
||||
***************************************/
|
||||
#ifdef _MSC_VER /* Visual Studio */
|
||||
# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
|
||||
# define FORCE_INLINE static __forceinline
|
||||
#else
|
||||
# if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
|
||||
# ifdef __GNUC__
|
||||
# define FORCE_INLINE static inline __attribute__((always_inline))
|
||||
# else
|
||||
# define FORCE_INLINE static inline
|
||||
# endif
|
||||
# else
|
||||
# define FORCE_INLINE static
|
||||
# endif /* __STDC_VERSION__ */
|
||||
#endif
|
||||
|
||||
|
||||
/**************************************
|
||||
* Includes & Memory related functions
|
||||
***************************************/
|
||||
#include "xxhash.h"
|
||||
/* Modify the local functions below should you wish to use some other memory routines */
|
||||
/* for malloc(), free() */
|
||||
#include <stdlib.h>
|
||||
static void* XXH_malloc(size_t s) { return malloc(s); }
|
||||
static void XXH_free (void* p) { free(p); }
|
||||
/* for memcpy() */
|
||||
#include <string.h>
|
||||
static void* XXH_memcpy(void* dest, const void* src, size_t size) { return memcpy(dest,src,size); }
|
||||
|
||||
|
||||
/**************************************
|
||||
* Basic Types
|
||||
***************************************/
|
||||
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
|
||||
# include <stdint.h>
|
||||
typedef uint8_t BYTE;
|
||||
typedef uint16_t U16;
|
||||
typedef uint32_t U32;
|
||||
typedef int32_t S32;
|
||||
typedef uint64_t U64;
|
||||
#else
|
||||
typedef unsigned char BYTE;
|
||||
typedef unsigned short U16;
|
||||
typedef unsigned int U32;
|
||||
typedef signed int S32;
|
||||
typedef unsigned long long U64;
|
||||
#endif
|
||||
|
||||
|
||||
#if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==2))
|
||||
|
||||
/* Force direct memory access. Only works on CPU which support unaligned memory access in hardware */
|
||||
static U32 XXH_read32(const void* memPtr) { return *(const U32*) memPtr; }
|
||||
static U64 XXH_read64(const void* memPtr) { return *(const U64*) memPtr; }
|
||||
|
||||
#elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==1))
|
||||
|
||||
/* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */
|
||||
/* currently only defined for gcc and icc */
|
||||
typedef union { U32 u32; U64 u64; } __attribute__((packed)) unalign;
|
||||
|
||||
static U32 XXH_read32(const void* ptr) { return ((const unalign*)ptr)->u32; }
|
||||
static U64 XXH_read64(const void* ptr) { return ((const unalign*)ptr)->u64; }
|
||||
|
||||
#else
|
||||
|
||||
/* portable and safe solution. Generally efficient.
|
||||
* see : http://stackoverflow.com/a/32095106/646947
|
||||
*/
|
||||
|
||||
static U32 XXH_read32(const void* memPtr)
|
||||
{
|
||||
U32 val;
|
||||
memcpy(&val, memPtr, sizeof(val));
|
||||
return val;
|
||||
}
|
||||
|
||||
static U64 XXH_read64(const void* memPtr)
|
||||
{
|
||||
U64 val;
|
||||
memcpy(&val, memPtr, sizeof(val));
|
||||
return val;
|
||||
}
|
||||
|
||||
#endif // XXH_FORCE_DIRECT_MEMORY_ACCESS
|
||||
|
||||
|
||||
/******************************************
|
||||
* Compiler-specific Functions and Macros
|
||||
******************************************/
|
||||
#define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
|
||||
|
||||
/* Note : although _rotl exists for minGW (GCC under windows), performance seems poor */
|
||||
#if defined(_MSC_VER)
|
||||
# define XXH_rotl32(x,r) _rotl(x,r)
|
||||
# define XXH_rotl64(x,r) _rotl64(x,r)
|
||||
#else
|
||||
# define XXH_rotl32(x,r) ((x << r) | (x >> (32 - r)))
|
||||
# define XXH_rotl64(x,r) ((x << r) | (x >> (64 - r)))
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) /* Visual Studio */
|
||||
# define XXH_swap32 _byteswap_ulong
|
||||
# define XXH_swap64 _byteswap_uint64
|
||||
#elif GCC_VERSION >= 403
|
||||
# define XXH_swap32 __builtin_bswap32
|
||||
# define XXH_swap64 __builtin_bswap64
|
||||
#else
|
||||
static U32 XXH_swap32 (U32 x)
|
||||
{
|
||||
return ((x << 24) & 0xff000000 ) |
|
||||
((x << 8) & 0x00ff0000 ) |
|
||||
((x >> 8) & 0x0000ff00 ) |
|
||||
((x >> 24) & 0x000000ff );
|
||||
}
|
||||
static U64 XXH_swap64 (U64 x)
|
||||
{
|
||||
return ((x << 56) & 0xff00000000000000ULL) |
|
||||
((x << 40) & 0x00ff000000000000ULL) |
|
||||
((x << 24) & 0x0000ff0000000000ULL) |
|
||||
((x << 8) & 0x000000ff00000000ULL) |
|
||||
((x >> 8) & 0x00000000ff000000ULL) |
|
||||
((x >> 24) & 0x0000000000ff0000ULL) |
|
||||
((x >> 40) & 0x000000000000ff00ULL) |
|
||||
((x >> 56) & 0x00000000000000ffULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/***************************************
|
||||
* Architecture Macros
|
||||
***************************************/
|
||||
typedef enum { XXH_bigEndian=0, XXH_littleEndian=1 } XXH_endianess;
|
||||
|
||||
/* XXH_CPU_LITTLE_ENDIAN can be defined externally, for example one the compiler command line */
|
||||
#ifndef XXH_CPU_LITTLE_ENDIAN
|
||||
static const int one = 1;
|
||||
# define XXH_CPU_LITTLE_ENDIAN (*(const char*)(&one))
|
||||
#endif
|
||||
|
||||
|
||||
/*****************************
|
||||
* Memory reads
|
||||
*****************************/
|
||||
typedef enum { XXH_aligned, XXH_unaligned } XXH_alignment;
|
||||
|
||||
FORCE_INLINE U32 XXH_readLE32_align(const void* ptr, XXH_endianess endian, XXH_alignment align)
|
||||
{
|
||||
if (align==XXH_unaligned)
|
||||
return endian==XXH_littleEndian ? XXH_read32(ptr) : XXH_swap32(XXH_read32(ptr));
|
||||
else
|
||||
return endian==XXH_littleEndian ? *(const U32*)ptr : XXH_swap32(*(const U32*)ptr);
|
||||
}
|
||||
|
||||
FORCE_INLINE U32 XXH_readLE32(const void* ptr, XXH_endianess endian)
|
||||
{
|
||||
return XXH_readLE32_align(ptr, endian, XXH_unaligned);
|
||||
}
|
||||
|
||||
FORCE_INLINE U64 XXH_readLE64_align(const void* ptr, XXH_endianess endian, XXH_alignment align)
|
||||
{
|
||||
if (align==XXH_unaligned)
|
||||
return endian==XXH_littleEndian ? XXH_read64(ptr) : XXH_swap64(XXH_read64(ptr));
|
||||
else
|
||||
return endian==XXH_littleEndian ? *(const U64*)ptr : XXH_swap64(*(const U64*)ptr);
|
||||
}
|
||||
|
||||
FORCE_INLINE U64 XXH_readLE64(const void* ptr, XXH_endianess endian)
|
||||
{
|
||||
return XXH_readLE64_align(ptr, endian, XXH_unaligned);
|
||||
}
|
||||
|
||||
|
||||
/***************************************
|
||||
* Macros
|
||||
***************************************/
|
||||
#define XXH_STATIC_ASSERT(c) { enum { XXH_static_assert = 1/(!!(c)) }; } /* use only *after* variable declarations */
|
||||
|
||||
|
||||
/***************************************
|
||||
* Constants
|
||||
***************************************/
|
||||
#define PRIME32_1 2654435761U
|
||||
#define PRIME32_2 2246822519U
|
||||
#define PRIME32_3 3266489917U
|
||||
#define PRIME32_4 668265263U
|
||||
#define PRIME32_5 374761393U
|
||||
|
||||
#define PRIME64_1 11400714785074694791ULL
|
||||
#define PRIME64_2 14029467366897019727ULL
|
||||
#define PRIME64_3 1609587929392839161ULL
|
||||
#define PRIME64_4 9650029242287828579ULL
|
||||
#define PRIME64_5 2870177450012600261ULL
|
||||
|
||||
|
||||
/*****************************
|
||||
* Simple Hash Functions
|
||||
*****************************/
|
||||
FORCE_INLINE U32 XXH32_endian_align(const void* input, size_t len, U32 seed, XXH_endianess endian, XXH_alignment align)
|
||||
{
|
||||
const BYTE* p = (const BYTE*)input;
|
||||
const BYTE* bEnd = p + len;
|
||||
U32 h32;
|
||||
#define XXH_get32bits(p) XXH_readLE32_align(p, endian, align)
|
||||
|
||||
#ifdef XXH_ACCEPT_NULL_INPUT_POINTER
|
||||
if (p==NULL)
|
||||
{
|
||||
len=0;
|
||||
bEnd=p=(const BYTE*)(size_t)16;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (len>=16)
|
||||
{
|
||||
const BYTE* const limit = bEnd - 16;
|
||||
U32 v1 = seed + PRIME32_1 + PRIME32_2;
|
||||
U32 v2 = seed + PRIME32_2;
|
||||
U32 v3 = seed + 0;
|
||||
U32 v4 = seed - PRIME32_1;
|
||||
|
||||
do
|
||||
{
|
||||
v1 += XXH_get32bits(p) * PRIME32_2;
|
||||
v1 = XXH_rotl32(v1, 13);
|
||||
v1 *= PRIME32_1;
|
||||
p+=4;
|
||||
v2 += XXH_get32bits(p) * PRIME32_2;
|
||||
v2 = XXH_rotl32(v2, 13);
|
||||
v2 *= PRIME32_1;
|
||||
p+=4;
|
||||
v3 += XXH_get32bits(p) * PRIME32_2;
|
||||
v3 = XXH_rotl32(v3, 13);
|
||||
v3 *= PRIME32_1;
|
||||
p+=4;
|
||||
v4 += XXH_get32bits(p) * PRIME32_2;
|
||||
v4 = XXH_rotl32(v4, 13);
|
||||
v4 *= PRIME32_1;
|
||||
p+=4;
|
||||
}
|
||||
while (p<=limit);
|
||||
|
||||
h32 = XXH_rotl32(v1, 1) + XXH_rotl32(v2, 7) + XXH_rotl32(v3, 12) + XXH_rotl32(v4, 18);
|
||||
}
|
||||
else
|
||||
{
|
||||
h32 = seed + PRIME32_5;
|
||||
}
|
||||
|
||||
h32 += (U32) len;
|
||||
|
||||
while (p+4<=bEnd)
|
||||
{
|
||||
h32 += XXH_get32bits(p) * PRIME32_3;
|
||||
h32 = XXH_rotl32(h32, 17) * PRIME32_4 ;
|
||||
p+=4;
|
||||
}
|
||||
|
||||
while (p<bEnd)
|
||||
{
|
||||
h32 += (*p) * PRIME32_5;
|
||||
h32 = XXH_rotl32(h32, 11) * PRIME32_1 ;
|
||||
p++;
|
||||
}
|
||||
|
||||
h32 ^= h32 >> 15;
|
||||
h32 *= PRIME32_2;
|
||||
h32 ^= h32 >> 13;
|
||||
h32 *= PRIME32_3;
|
||||
h32 ^= h32 >> 16;
|
||||
|
||||
return h32;
|
||||
}
|
||||
|
||||
|
||||
unsigned int XXH32 (const void* input, size_t len, unsigned int seed)
|
||||
{
|
||||
#if 0
|
||||
/* Simple version, good for code maintenance, but unfortunately slow for small inputs */
|
||||
XXH32_state_t state;
|
||||
XXH32_reset(&state, seed);
|
||||
XXH32_update(&state, input, len);
|
||||
return XXH32_digest(&state);
|
||||
#else
|
||||
XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
|
||||
|
||||
# if !defined(XXH_USELESS_ALIGN_BRANCH)
|
||||
if ((((size_t)input) & 3) == 0) /* Input is 4-bytes aligned, leverage the speed benefit */
|
||||
{
|
||||
if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
|
||||
return XXH32_endian_align(input, len, seed, XXH_littleEndian, XXH_aligned);
|
||||
else
|
||||
return XXH32_endian_align(input, len, seed, XXH_bigEndian, XXH_aligned);
|
||||
}
|
||||
# endif
|
||||
|
||||
if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
|
||||
return XXH32_endian_align(input, len, seed, XXH_littleEndian, XXH_unaligned);
|
||||
else
|
||||
return XXH32_endian_align(input, len, seed, XXH_bigEndian, XXH_unaligned);
|
||||
#endif
|
||||
}
|
||||
|
||||
FORCE_INLINE U64 XXH64_endian_align(const void* input, size_t len, U64 seed, XXH_endianess endian, XXH_alignment align)
|
||||
{
|
||||
const BYTE* p = (const BYTE*)input;
|
||||
const BYTE* bEnd = p + len;
|
||||
U64 h64;
|
||||
#define XXH_get64bits(p) XXH_readLE64_align(p, endian, align)
|
||||
|
||||
#ifdef XXH_ACCEPT_NULL_INPUT_POINTER
|
||||
if (p==NULL)
|
||||
{
|
||||
len=0;
|
||||
bEnd=p=(const BYTE*)(size_t)32;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (len>=32)
|
||||
{
|
||||
const BYTE* const limit = bEnd - 32;
|
||||
U64 v1 = seed + PRIME64_1 + PRIME64_2;
|
||||
U64 v2 = seed + PRIME64_2;
|
||||
U64 v3 = seed + 0;
|
||||
U64 v4 = seed - PRIME64_1;
|
||||
|
||||
do
|
||||
{
|
||||
v1 += XXH_get64bits(p) * PRIME64_2;
|
||||
p+=8;
|
||||
v1 = XXH_rotl64(v1, 31);
|
||||
v1 *= PRIME64_1;
|
||||
v2 += XXH_get64bits(p) * PRIME64_2;
|
||||
p+=8;
|
||||
v2 = XXH_rotl64(v2, 31);
|
||||
v2 *= PRIME64_1;
|
||||
v3 += XXH_get64bits(p) * PRIME64_2;
|
||||
p+=8;
|
||||
v3 = XXH_rotl64(v3, 31);
|
||||
v3 *= PRIME64_1;
|
||||
v4 += XXH_get64bits(p) * PRIME64_2;
|
||||
p+=8;
|
||||
v4 = XXH_rotl64(v4, 31);
|
||||
v4 *= PRIME64_1;
|
||||
}
|
||||
while (p<=limit);
|
||||
|
||||
h64 = XXH_rotl64(v1, 1) + XXH_rotl64(v2, 7) + XXH_rotl64(v3, 12) + XXH_rotl64(v4, 18);
|
||||
|
||||
v1 *= PRIME64_2;
|
||||
v1 = XXH_rotl64(v1, 31);
|
||||
v1 *= PRIME64_1;
|
||||
h64 ^= v1;
|
||||
h64 = h64 * PRIME64_1 + PRIME64_4;
|
||||
|
||||
v2 *= PRIME64_2;
|
||||
v2 = XXH_rotl64(v2, 31);
|
||||
v2 *= PRIME64_1;
|
||||
h64 ^= v2;
|
||||
h64 = h64 * PRIME64_1 + PRIME64_4;
|
||||
|
||||
v3 *= PRIME64_2;
|
||||
v3 = XXH_rotl64(v3, 31);
|
||||
v3 *= PRIME64_1;
|
||||
h64 ^= v3;
|
||||
h64 = h64 * PRIME64_1 + PRIME64_4;
|
||||
|
||||
v4 *= PRIME64_2;
|
||||
v4 = XXH_rotl64(v4, 31);
|
||||
v4 *= PRIME64_1;
|
||||
h64 ^= v4;
|
||||
h64 = h64 * PRIME64_1 + PRIME64_4;
|
||||
}
|
||||
else
|
||||
{
|
||||
h64 = seed + PRIME64_5;
|
||||
}
|
||||
|
||||
h64 += (U64) len;
|
||||
|
||||
while (p+8<=bEnd)
|
||||
{
|
||||
U64 k1 = XXH_get64bits(p);
|
||||
k1 *= PRIME64_2;
|
||||
k1 = XXH_rotl64(k1,31);
|
||||
k1 *= PRIME64_1;
|
||||
h64 ^= k1;
|
||||
h64 = XXH_rotl64(h64,27) * PRIME64_1 + PRIME64_4;
|
||||
p+=8;
|
||||
}
|
||||
|
||||
if (p+4<=bEnd)
|
||||
{
|
||||
h64 ^= (U64)(XXH_get32bits(p)) * PRIME64_1;
|
||||
h64 = XXH_rotl64(h64, 23) * PRIME64_2 + PRIME64_3;
|
||||
p+=4;
|
||||
}
|
||||
|
||||
while (p<bEnd)
|
||||
{
|
||||
h64 ^= (*p) * PRIME64_5;
|
||||
h64 = XXH_rotl64(h64, 11) * PRIME64_1;
|
||||
p++;
|
||||
}
|
||||
|
||||
h64 ^= h64 >> 33;
|
||||
h64 *= PRIME64_2;
|
||||
h64 ^= h64 >> 29;
|
||||
h64 *= PRIME64_3;
|
||||
h64 ^= h64 >> 32;
|
||||
|
||||
return h64;
|
||||
}
|
||||
|
||||
|
||||
unsigned long long XXH64 (const void* input, size_t len, unsigned long long seed)
|
||||
{
|
||||
#if 0
|
||||
/* Simple version, good for code maintenance, but unfortunately slow for small inputs */
|
||||
XXH64_state_t state;
|
||||
XXH64_reset(&state, seed);
|
||||
XXH64_update(&state, input, len);
|
||||
return XXH64_digest(&state);
|
||||
#else
|
||||
XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
|
||||
|
||||
# if !defined(XXH_USELESS_ALIGN_BRANCH)
|
||||
if ((((size_t)input) & 7)==0) /* Input is aligned, let's leverage the speed advantage */
|
||||
{
|
||||
if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
|
||||
return XXH64_endian_align(input, len, seed, XXH_littleEndian, XXH_aligned);
|
||||
else
|
||||
return XXH64_endian_align(input, len, seed, XXH_bigEndian, XXH_aligned);
|
||||
}
|
||||
# endif
|
||||
|
||||
if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
|
||||
return XXH64_endian_align(input, len, seed, XXH_littleEndian, XXH_unaligned);
|
||||
else
|
||||
return XXH64_endian_align(input, len, seed, XXH_bigEndian, XXH_unaligned);
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************
|
||||
* Advanced Hash Functions
|
||||
****************************************************/
|
||||
|
||||
/*** Allocation ***/
|
||||
typedef struct
|
||||
{
|
||||
U64 total_len;
|
||||
U32 seed;
|
||||
U32 v1;
|
||||
U32 v2;
|
||||
U32 v3;
|
||||
U32 v4;
|
||||
U32 mem32[4]; /* defined as U32 for alignment */
|
||||
U32 memsize;
|
||||
} XXH_istate32_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
U64 total_len;
|
||||
U64 seed;
|
||||
U64 v1;
|
||||
U64 v2;
|
||||
U64 v3;
|
||||
U64 v4;
|
||||
U64 mem64[4]; /* defined as U64 for alignment */
|
||||
U32 memsize;
|
||||
} XXH_istate64_t;
|
||||
|
||||
|
||||
XXH32_state_t* XXH32_createState(void)
|
||||
{
|
||||
XXH_STATIC_ASSERT(sizeof(XXH32_state_t) >= sizeof(XXH_istate32_t)); /* A compilation error here means XXH32_state_t is not large enough */
|
||||
return (XXH32_state_t*)XXH_malloc(sizeof(XXH32_state_t));
|
||||
}
|
||||
XXH_errorcode XXH32_freeState(XXH32_state_t* statePtr)
|
||||
{
|
||||
XXH_free(statePtr);
|
||||
return XXH_OK;
|
||||
}
|
||||
|
||||
XXH64_state_t* XXH64_createState(void)
|
||||
{
|
||||
XXH_STATIC_ASSERT(sizeof(XXH64_state_t) >= sizeof(XXH_istate64_t)); /* A compilation error here means XXH64_state_t is not large enough */
|
||||
return (XXH64_state_t*)XXH_malloc(sizeof(XXH64_state_t));
|
||||
}
|
||||
XXH_errorcode XXH64_freeState(XXH64_state_t* statePtr)
|
||||
{
|
||||
XXH_free(statePtr);
|
||||
return XXH_OK;
|
||||
}
|
||||
|
||||
|
||||
/*** Hash feed ***/
|
||||
|
||||
XXH_errorcode XXH32_reset(XXH32_state_t* state_in, unsigned int seed)
|
||||
{
|
||||
XXH_istate32_t* state = (XXH_istate32_t*) state_in;
|
||||
state->seed = seed;
|
||||
state->v1 = seed + PRIME32_1 + PRIME32_2;
|
||||
state->v2 = seed + PRIME32_2;
|
||||
state->v3 = seed + 0;
|
||||
state->v4 = seed - PRIME32_1;
|
||||
state->total_len = 0;
|
||||
state->memsize = 0;
|
||||
return XXH_OK;
|
||||
}
|
||||
|
||||
XXH_errorcode XXH64_reset(XXH64_state_t* state_in, unsigned long long seed)
|
||||
{
|
||||
XXH_istate64_t* state = (XXH_istate64_t*) state_in;
|
||||
state->seed = seed;
|
||||
state->v1 = seed + PRIME64_1 + PRIME64_2;
|
||||
state->v2 = seed + PRIME64_2;
|
||||
state->v3 = seed + 0;
|
||||
state->v4 = seed - PRIME64_1;
|
||||
state->total_len = 0;
|
||||
state->memsize = 0;
|
||||
return XXH_OK;
|
||||
}
|
||||
|
||||
|
||||
FORCE_INLINE XXH_errorcode XXH32_update_endian (XXH32_state_t* state_in, const void* input, size_t len, XXH_endianess endian)
|
||||
{
|
||||
XXH_istate32_t* state = (XXH_istate32_t *) state_in;
|
||||
const BYTE* p = (const BYTE*)input;
|
||||
const BYTE* const bEnd = p + len;
|
||||
|
||||
#ifdef XXH_ACCEPT_NULL_INPUT_POINTER
|
||||
if (input==NULL) return XXH_ERROR;
|
||||
#endif
|
||||
|
||||
state->total_len += len;
|
||||
|
||||
if (state->memsize + len < 16) /* fill in tmp buffer */
|
||||
{
|
||||
XXH_memcpy((BYTE*)(state->mem32) + state->memsize, input, len);
|
||||
state->memsize += (U32)len;
|
||||
return XXH_OK;
|
||||
}
|
||||
|
||||
if (state->memsize) /* some data left from previous update */
|
||||
{
|
||||
XXH_memcpy((BYTE*)(state->mem32) + state->memsize, input, 16-state->memsize);
|
||||
{
|
||||
const U32* p32 = state->mem32;
|
||||
state->v1 += XXH_readLE32(p32, endian) * PRIME32_2;
|
||||
state->v1 = XXH_rotl32(state->v1, 13);
|
||||
state->v1 *= PRIME32_1;
|
||||
p32++;
|
||||
state->v2 += XXH_readLE32(p32, endian) * PRIME32_2;
|
||||
state->v2 = XXH_rotl32(state->v2, 13);
|
||||
state->v2 *= PRIME32_1;
|
||||
p32++;
|
||||
state->v3 += XXH_readLE32(p32, endian) * PRIME32_2;
|
||||
state->v3 = XXH_rotl32(state->v3, 13);
|
||||
state->v3 *= PRIME32_1;
|
||||
p32++;
|
||||
state->v4 += XXH_readLE32(p32, endian) * PRIME32_2;
|
||||
state->v4 = XXH_rotl32(state->v4, 13);
|
||||
state->v4 *= PRIME32_1;
|
||||
p32++;
|
||||
}
|
||||
p += 16-state->memsize;
|
||||
state->memsize = 0;
|
||||
}
|
||||
|
||||
if (p <= bEnd-16)
|
||||
{
|
||||
const BYTE* const limit = bEnd - 16;
|
||||
U32 v1 = state->v1;
|
||||
U32 v2 = state->v2;
|
||||
U32 v3 = state->v3;
|
||||
U32 v4 = state->v4;
|
||||
|
||||
do
|
||||
{
|
||||
v1 += XXH_readLE32(p, endian) * PRIME32_2;
|
||||
v1 = XXH_rotl32(v1, 13);
|
||||
v1 *= PRIME32_1;
|
||||
p+=4;
|
||||
v2 += XXH_readLE32(p, endian) * PRIME32_2;
|
||||
v2 = XXH_rotl32(v2, 13);
|
||||
v2 *= PRIME32_1;
|
||||
p+=4;
|
||||
v3 += XXH_readLE32(p, endian) * PRIME32_2;
|
||||
v3 = XXH_rotl32(v3, 13);
|
||||
v3 *= PRIME32_1;
|
||||
p+=4;
|
||||
v4 += XXH_readLE32(p, endian) * PRIME32_2;
|
||||
v4 = XXH_rotl32(v4, 13);
|
||||
v4 *= PRIME32_1;
|
||||
p+=4;
|
||||
}
|
||||
while (p<=limit);
|
||||
|
||||
state->v1 = v1;
|
||||
state->v2 = v2;
|
||||
state->v3 = v3;
|
||||
state->v4 = v4;
|
||||
}
|
||||
|
||||
if (p < bEnd)
|
||||
{
|
||||
XXH_memcpy(state->mem32, p, bEnd-p);
|
||||
state->memsize = (int)(bEnd-p);
|
||||
}
|
||||
|
||||
return XXH_OK;
|
||||
}
|
||||
|
||||
XXH_errorcode XXH32_update (XXH32_state_t* state_in, const void* input, size_t len)
|
||||
{
|
||||
XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
|
||||
|
||||
if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
|
||||
return XXH32_update_endian(state_in, input, len, XXH_littleEndian);
|
||||
else
|
||||
return XXH32_update_endian(state_in, input, len, XXH_bigEndian);
|
||||
}
|
||||
|
||||
|
||||
|
||||
FORCE_INLINE U32 XXH32_digest_endian (const XXH32_state_t* state_in, XXH_endianess endian)
|
||||
{
|
||||
const XXH_istate32_t* state = (const XXH_istate32_t*) state_in;
|
||||
const BYTE * p = (const BYTE*)state->mem32;
|
||||
const BYTE* bEnd = (const BYTE*)(state->mem32) + state->memsize;
|
||||
U32 h32;
|
||||
|
||||
if (state->total_len >= 16)
|
||||
{
|
||||
h32 = XXH_rotl32(state->v1, 1) + XXH_rotl32(state->v2, 7) + XXH_rotl32(state->v3, 12) + XXH_rotl32(state->v4, 18);
|
||||
}
|
||||
else
|
||||
{
|
||||
h32 = state->seed + PRIME32_5;
|
||||
}
|
||||
|
||||
h32 += (U32) state->total_len;
|
||||
|
||||
while (p+4<=bEnd)
|
||||
{
|
||||
h32 += XXH_readLE32(p, endian) * PRIME32_3;
|
||||
h32 = XXH_rotl32(h32, 17) * PRIME32_4;
|
||||
p+=4;
|
||||
}
|
||||
|
||||
while (p<bEnd)
|
||||
{
|
||||
h32 += (*p) * PRIME32_5;
|
||||
h32 = XXH_rotl32(h32, 11) * PRIME32_1;
|
||||
p++;
|
||||
}
|
||||
|
||||
h32 ^= h32 >> 15;
|
||||
h32 *= PRIME32_2;
|
||||
h32 ^= h32 >> 13;
|
||||
h32 *= PRIME32_3;
|
||||
h32 ^= h32 >> 16;
|
||||
|
||||
return h32;
|
||||
}
|
||||
|
||||
|
||||
unsigned int XXH32_digest (const XXH32_state_t* state_in)
|
||||
{
|
||||
XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
|
||||
|
||||
if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
|
||||
return XXH32_digest_endian(state_in, XXH_littleEndian);
|
||||
else
|
||||
return XXH32_digest_endian(state_in, XXH_bigEndian);
|
||||
}
|
||||
|
||||
|
||||
FORCE_INLINE XXH_errorcode XXH64_update_endian (XXH64_state_t* state_in, const void* input, size_t len, XXH_endianess endian)
|
||||
{
|
||||
XXH_istate64_t * state = (XXH_istate64_t *) state_in;
|
||||
const BYTE* p = (const BYTE*)input;
|
||||
const BYTE* const bEnd = p + len;
|
||||
|
||||
#ifdef XXH_ACCEPT_NULL_INPUT_POINTER
|
||||
if (input==NULL) return XXH_ERROR;
|
||||
#endif
|
||||
|
||||
state->total_len += len;
|
||||
|
||||
if (state->memsize + len < 32) /* fill in tmp buffer */
|
||||
{
|
||||
XXH_memcpy(((BYTE*)state->mem64) + state->memsize, input, len);
|
||||
state->memsize += (U32)len;
|
||||
return XXH_OK;
|
||||
}
|
||||
|
||||
if (state->memsize) /* some data left from previous update */
|
||||
{
|
||||
XXH_memcpy(((BYTE*)state->mem64) + state->memsize, input, 32-state->memsize);
|
||||
{
|
||||
const U64* p64 = state->mem64;
|
||||
state->v1 += XXH_readLE64(p64, endian) * PRIME64_2;
|
||||
state->v1 = XXH_rotl64(state->v1, 31);
|
||||
state->v1 *= PRIME64_1;
|
||||
p64++;
|
||||
state->v2 += XXH_readLE64(p64, endian) * PRIME64_2;
|
||||
state->v2 = XXH_rotl64(state->v2, 31);
|
||||
state->v2 *= PRIME64_1;
|
||||
p64++;
|
||||
state->v3 += XXH_readLE64(p64, endian) * PRIME64_2;
|
||||
state->v3 = XXH_rotl64(state->v3, 31);
|
||||
state->v3 *= PRIME64_1;
|
||||
p64++;
|
||||
state->v4 += XXH_readLE64(p64, endian) * PRIME64_2;
|
||||
state->v4 = XXH_rotl64(state->v4, 31);
|
||||
state->v4 *= PRIME64_1;
|
||||
p64++;
|
||||
}
|
||||
p += 32-state->memsize;
|
||||
state->memsize = 0;
|
||||
}
|
||||
|
||||
if (p+32 <= bEnd)
|
||||
{
|
||||
const BYTE* const limit = bEnd - 32;
|
||||
U64 v1 = state->v1;
|
||||
U64 v2 = state->v2;
|
||||
U64 v3 = state->v3;
|
||||
U64 v4 = state->v4;
|
||||
|
||||
do
|
||||
{
|
||||
v1 += XXH_readLE64(p, endian) * PRIME64_2;
|
||||
v1 = XXH_rotl64(v1, 31);
|
||||
v1 *= PRIME64_1;
|
||||
p+=8;
|
||||
v2 += XXH_readLE64(p, endian) * PRIME64_2;
|
||||
v2 = XXH_rotl64(v2, 31);
|
||||
v2 *= PRIME64_1;
|
||||
p+=8;
|
||||
v3 += XXH_readLE64(p, endian) * PRIME64_2;
|
||||
v3 = XXH_rotl64(v3, 31);
|
||||
v3 *= PRIME64_1;
|
||||
p+=8;
|
||||
v4 += XXH_readLE64(p, endian) * PRIME64_2;
|
||||
v4 = XXH_rotl64(v4, 31);
|
||||
v4 *= PRIME64_1;
|
||||
p+=8;
|
||||
}
|
||||
while (p<=limit);
|
||||
|
||||
state->v1 = v1;
|
||||
state->v2 = v2;
|
||||
state->v3 = v3;
|
||||
state->v4 = v4;
|
||||
}
|
||||
|
||||
if (p < bEnd)
|
||||
{
|
||||
XXH_memcpy(state->mem64, p, bEnd-p);
|
||||
state->memsize = (int)(bEnd-p);
|
||||
}
|
||||
|
||||
return XXH_OK;
|
||||
}
|
||||
|
||||
XXH_errorcode XXH64_update (XXH64_state_t* state_in, const void* input, size_t len)
|
||||
{
|
||||
XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
|
||||
|
||||
if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
|
||||
return XXH64_update_endian(state_in, input, len, XXH_littleEndian);
|
||||
else
|
||||
return XXH64_update_endian(state_in, input, len, XXH_bigEndian);
|
||||
}
|
||||
|
||||
|
||||
|
||||
FORCE_INLINE U64 XXH64_digest_endian (const XXH64_state_t* state_in, XXH_endianess endian)
|
||||
{
|
||||
const XXH_istate64_t * state = (const XXH_istate64_t *) state_in;
|
||||
const BYTE * p = (const BYTE*)state->mem64;
|
||||
const BYTE* bEnd = (const BYTE*)state->mem64 + state->memsize;
|
||||
U64 h64;
|
||||
|
||||
if (state->total_len >= 32)
|
||||
{
|
||||
U64 v1 = state->v1;
|
||||
U64 v2 = state->v2;
|
||||
U64 v3 = state->v3;
|
||||
U64 v4 = state->v4;
|
||||
|
||||
h64 = XXH_rotl64(v1, 1) + XXH_rotl64(v2, 7) + XXH_rotl64(v3, 12) + XXH_rotl64(v4, 18);
|
||||
|
||||
v1 *= PRIME64_2;
|
||||
v1 = XXH_rotl64(v1, 31);
|
||||
v1 *= PRIME64_1;
|
||||
h64 ^= v1;
|
||||
h64 = h64*PRIME64_1 + PRIME64_4;
|
||||
|
||||
v2 *= PRIME64_2;
|
||||
v2 = XXH_rotl64(v2, 31);
|
||||
v2 *= PRIME64_1;
|
||||
h64 ^= v2;
|
||||
h64 = h64*PRIME64_1 + PRIME64_4;
|
||||
|
||||
v3 *= PRIME64_2;
|
||||
v3 = XXH_rotl64(v3, 31);
|
||||
v3 *= PRIME64_1;
|
||||
h64 ^= v3;
|
||||
h64 = h64*PRIME64_1 + PRIME64_4;
|
||||
|
||||
v4 *= PRIME64_2;
|
||||
v4 = XXH_rotl64(v4, 31);
|
||||
v4 *= PRIME64_1;
|
||||
h64 ^= v4;
|
||||
h64 = h64*PRIME64_1 + PRIME64_4;
|
||||
}
|
||||
else
|
||||
{
|
||||
h64 = state->seed + PRIME64_5;
|
||||
}
|
||||
|
||||
h64 += (U64) state->total_len;
|
||||
|
||||
while (p+8<=bEnd)
|
||||
{
|
||||
U64 k1 = XXH_readLE64(p, endian);
|
||||
k1 *= PRIME64_2;
|
||||
k1 = XXH_rotl64(k1,31);
|
||||
k1 *= PRIME64_1;
|
||||
h64 ^= k1;
|
||||
h64 = XXH_rotl64(h64,27) * PRIME64_1 + PRIME64_4;
|
||||
p+=8;
|
||||
}
|
||||
|
||||
if (p+4<=bEnd)
|
||||
{
|
||||
h64 ^= (U64)(XXH_readLE32(p, endian)) * PRIME64_1;
|
||||
h64 = XXH_rotl64(h64, 23) * PRIME64_2 + PRIME64_3;
|
||||
p+=4;
|
||||
}
|
||||
|
||||
while (p<bEnd)
|
||||
{
|
||||
h64 ^= (*p) * PRIME64_5;
|
||||
h64 = XXH_rotl64(h64, 11) * PRIME64_1;
|
||||
p++;
|
||||
}
|
||||
|
||||
h64 ^= h64 >> 33;
|
||||
h64 *= PRIME64_2;
|
||||
h64 ^= h64 >> 29;
|
||||
h64 *= PRIME64_3;
|
||||
h64 ^= h64 >> 32;
|
||||
|
||||
return h64;
|
||||
}
|
||||
|
||||
|
||||
unsigned long long XXH64_digest (const XXH64_state_t* state_in)
|
||||
{
|
||||
XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
|
||||
|
||||
if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
|
||||
return XXH64_digest_endian(state_in, XXH_littleEndian);
|
||||
else
|
||||
return XXH64_digest_endian(state_in, XXH_bigEndian);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,192 @@
|
|||
/*
|
||||
xxHash - Extremely Fast Hash algorithm
|
||||
Header File
|
||||
Copyright (C) 2012-2015, Yann Collet.
|
||||
|
||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
You can contact the author at :
|
||||
- xxHash source repository : https://github.com/Cyan4973/xxHash
|
||||
*/
|
||||
|
||||
/* Notice extracted from xxHash homepage :
|
||||
|
||||
xxHash is an extremely fast Hash algorithm, running at RAM speed limits.
|
||||
It also successfully passes all tests from the SMHasher suite.
|
||||
|
||||
Comparison (single thread, Windows Seven 32 bits, using SMHasher on a Core 2 Duo @3GHz)
|
||||
|
||||
Name Speed Q.Score Author
|
||||
xxHash 5.4 GB/s 10
|
||||
CrapWow 3.2 GB/s 2 Andrew
|
||||
MumurHash 3a 2.7 GB/s 10 Austin Appleby
|
||||
SpookyHash 2.0 GB/s 10 Bob Jenkins
|
||||
SBox 1.4 GB/s 9 Bret Mulvey
|
||||
Lookup3 1.2 GB/s 9 Bob Jenkins
|
||||
SuperFastHash 1.2 GB/s 1 Paul Hsieh
|
||||
CityHash64 1.05 GB/s 10 Pike & Alakuijala
|
||||
FNV 0.55 GB/s 5 Fowler, Noll, Vo
|
||||
CRC32 0.43 GB/s 9
|
||||
MD5-32 0.33 GB/s 10 Ronald L. Rivest
|
||||
SHA1-32 0.28 GB/s 10
|
||||
|
||||
Q.Score is a measure of quality of the hash function.
|
||||
It depends on successfully passing SMHasher test set.
|
||||
10 is a perfect score.
|
||||
|
||||
A 64-bits version, named XXH64, is available since r35.
|
||||
It offers much better speed, but for 64-bits applications only.
|
||||
Name Speed on 64 bits Speed on 32 bits
|
||||
XXH64 13.8 GB/s 1.9 GB/s
|
||||
XXH32 6.8 GB/s 6.0 GB/s
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/*****************************
|
||||
* Definitions
|
||||
*****************************/
|
||||
#include <stddef.h> /* size_t */
|
||||
typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode;
|
||||
|
||||
|
||||
/*****************************
|
||||
* Namespace Emulation
|
||||
*****************************/
|
||||
/* Motivations :
|
||||
|
||||
If you need to include xxHash into your library,
|
||||
but wish to avoid xxHash symbols to be present on your library interface
|
||||
in an effort to avoid potential name collision if another library also includes xxHash,
|
||||
|
||||
you can use XXH_NAMESPACE, which will automatically prefix any symbol from xxHash
|
||||
with the value of XXH_NAMESPACE (so avoid to keep it NULL, and avoid numeric values).
|
||||
|
||||
Note that no change is required within the calling program :
|
||||
it can still call xxHash functions using their regular name.
|
||||
They will be automatically translated by this header.
|
||||
*/
|
||||
#ifdef XXH_NAMESPACE
|
||||
# define XXH_CAT(A,B) A##B
|
||||
# define XXH_NAME2(A,B) XXH_CAT(A,B)
|
||||
# define XXH32 XXH_NAME2(XXH_NAMESPACE, XXH32)
|
||||
# define XXH64 XXH_NAME2(XXH_NAMESPACE, XXH64)
|
||||
# define XXH32_createState XXH_NAME2(XXH_NAMESPACE, XXH32_createState)
|
||||
# define XXH64_createState XXH_NAME2(XXH_NAMESPACE, XXH64_createState)
|
||||
# define XXH32_freeState XXH_NAME2(XXH_NAMESPACE, XXH32_freeState)
|
||||
# define XXH64_freeState XXH_NAME2(XXH_NAMESPACE, XXH64_freeState)
|
||||
# define XXH32_reset XXH_NAME2(XXH_NAMESPACE, XXH32_reset)
|
||||
# define XXH64_reset XXH_NAME2(XXH_NAMESPACE, XXH64_reset)
|
||||
# define XXH32_update XXH_NAME2(XXH_NAMESPACE, XXH32_update)
|
||||
# define XXH64_update XXH_NAME2(XXH_NAMESPACE, XXH64_update)
|
||||
# define XXH32_digest XXH_NAME2(XXH_NAMESPACE, XXH32_digest)
|
||||
# define XXH64_digest XXH_NAME2(XXH_NAMESPACE, XXH64_digest)
|
||||
#endif
|
||||
|
||||
|
||||
/*****************************
|
||||
* Simple Hash Functions
|
||||
*****************************/
|
||||
|
||||
unsigned int XXH32 (const void* input, size_t length, unsigned seed);
|
||||
unsigned long long XXH64 (const void* input, size_t length, unsigned long long seed);
|
||||
|
||||
/*
|
||||
XXH32() :
|
||||
Calculate the 32-bits hash of sequence "length" bytes stored at memory address "input".
|
||||
The memory between input & input+length must be valid (allocated and read-accessible).
|
||||
"seed" can be used to alter the result predictably.
|
||||
This function successfully passes all SMHasher tests.
|
||||
Speed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark) : 5.4 GB/s
|
||||
XXH64() :
|
||||
Calculate the 64-bits hash of sequence of length "len" stored at memory address "input".
|
||||
Faster on 64-bits systems. Slower on 32-bits systems.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*****************************
|
||||
* Advanced Hash Functions
|
||||
*****************************/
|
||||
typedef struct { long long ll[ 6]; } XXH32_state_t;
|
||||
typedef struct { long long ll[11]; } XXH64_state_t;
|
||||
|
||||
/*
|
||||
These structures allow static allocation of XXH states.
|
||||
States must then be initialized using XXHnn_reset() before first use.
|
||||
|
||||
If you prefer dynamic allocation, please refer to functions below.
|
||||
*/
|
||||
|
||||
XXH32_state_t* XXH32_createState(void);
|
||||
XXH_errorcode XXH32_freeState(XXH32_state_t* statePtr);
|
||||
|
||||
XXH64_state_t* XXH64_createState(void);
|
||||
XXH_errorcode XXH64_freeState(XXH64_state_t* statePtr);
|
||||
|
||||
/*
|
||||
These functions create and release memory for XXH state.
|
||||
States must then be initialized using XXHnn_reset() before first use.
|
||||
*/
|
||||
|
||||
|
||||
XXH_errorcode XXH32_reset (XXH32_state_t* statePtr, unsigned seed);
|
||||
XXH_errorcode XXH32_update (XXH32_state_t* statePtr, const void* input, size_t length);
|
||||
unsigned int XXH32_digest (const XXH32_state_t* statePtr);
|
||||
|
||||
XXH_errorcode XXH64_reset (XXH64_state_t* statePtr, unsigned long long seed);
|
||||
XXH_errorcode XXH64_update (XXH64_state_t* statePtr, const void* input, size_t length);
|
||||
unsigned long long XXH64_digest (const XXH64_state_t* statePtr);
|
||||
|
||||
/*
|
||||
These functions calculate the xxHash of an input provided in multiple smaller packets,
|
||||
as opposed to an input provided as a single block.
|
||||
|
||||
XXH state space must first be allocated, using either static or dynamic method provided above.
|
||||
|
||||
Start a new hash by initializing state with a seed, using XXHnn_reset().
|
||||
|
||||
Then, feed the hash state by calling XXHnn_update() as many times as necessary.
|
||||
Obviously, input must be valid, meaning allocated and read accessible.
|
||||
The function returns an error code, with 0 meaning OK, and any other value meaning there is an error.
|
||||
|
||||
Finally, you can produce a hash anytime, by using XXHnn_digest().
|
||||
This function returns the final nn-bits hash.
|
||||
You can nonetheless continue feeding the hash state with more input,
|
||||
and therefore get some new hashes, by calling again XXHnn_digest().
|
||||
|
||||
When you are done, don't forget to free XXH state space, using typically XXHnn_freeState().
|
||||
*/
|
||||
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
#endif
|
|
@ -28,7 +28,7 @@
|
|||
#include <regex>
|
||||
#include <LogVisor/LogVisor.hpp>
|
||||
#include <Athena/DNA.hpp>
|
||||
#include "../extern/blowfish/blowfish.h"
|
||||
#include "../extern/xxhash/xxhash.h"
|
||||
|
||||
/* Handy MIN/MAX macros */
|
||||
#ifndef MAX
|
||||
|
@ -63,10 +63,10 @@ class SystemUTF8View
|
|||
public:
|
||||
SystemUTF8View(const SystemString& str)
|
||||
: m_utf8(WideToUTF8(str)) {}
|
||||
inline operator const std::string&() const {return m_utf8;}
|
||||
inline const std::string& str() const {return m_utf8;}
|
||||
inline std::string operator+(const std::string& other) const {return m_utf8 + other;}
|
||||
inline std::string operator+(const char* other) const {return m_utf8 + other;}
|
||||
operator const std::string&() const {return m_utf8;}
|
||||
const std::string& str() const {return m_utf8;}
|
||||
std::string operator+(const std::string& other) const {return m_utf8 + other;}
|
||||
std::string operator+(const char* other) const {return m_utf8 + other;}
|
||||
};
|
||||
inline std::string operator+(const std::string& lhs, const SystemUTF8View& rhs) {return lhs + std::string(rhs);}
|
||||
inline std::string operator+(const char* lhs, const SystemUTF8View& rhs) {return lhs + std::string(rhs);}
|
||||
|
@ -76,10 +76,10 @@ class SystemStringView
|
|||
public:
|
||||
SystemStringView(const std::string& str)
|
||||
: m_sys(UTF8ToWide(str)) {}
|
||||
inline operator const std::wstring&() const {return m_sys;}
|
||||
inline const std::wstring& sys_str() const {return m_sys;}
|
||||
inline std::wstring operator+(const std::wstring& other) const {return m_sys + other;}
|
||||
inline std::wstring operator+(const wchar_t* other) const {return m_sys + other;}
|
||||
operator const std::wstring&() const {return m_sys;}
|
||||
const std::wstring& sys_str() const {return m_sys;}
|
||||
std::wstring operator+(const std::wstring& other) const {return m_sys + other;}
|
||||
std::wstring operator+(const wchar_t* other) const {return m_sys + other;}
|
||||
};
|
||||
inline std::wstring operator+(const std::wstring& lhs, const SystemStringView& rhs) {return lhs + std::wstring(rhs);}
|
||||
inline std::wstring operator+(const wchar_t* lhs, const SystemStringView& rhs) {return lhs + std::wstring(rhs);}
|
||||
|
@ -101,10 +101,10 @@ class SystemUTF8View
|
|||
public:
|
||||
SystemUTF8View(const SystemString& str)
|
||||
: m_utf8(str) {}
|
||||
inline operator const std::string&() const {return m_utf8;}
|
||||
inline const std::string& str() const {return m_utf8;}
|
||||
inline std::string operator+(const std::string& other) const {return std::string(m_utf8) + other;}
|
||||
inline std::string operator+(const char* other) const {return std::string(m_utf8) + other;}
|
||||
operator const std::string&() const {return m_utf8;}
|
||||
const std::string& str() const {return m_utf8;}
|
||||
std::string operator+(const std::string& other) const {return std::string(m_utf8) + other;}
|
||||
std::string operator+(const char* other) const {return std::string(m_utf8) + other;}
|
||||
};
|
||||
inline std::string operator+(const std::string& lhs, const SystemUTF8View& rhs) {return lhs + std::string(rhs);}
|
||||
inline std::string operator+(const char* lhs, const SystemUTF8View& rhs) {return lhs + std::string(rhs);}
|
||||
|
@ -114,10 +114,10 @@ class SystemStringView
|
|||
public:
|
||||
SystemStringView(const std::string& str)
|
||||
: m_sys(str) {}
|
||||
inline operator const std::string&() const {return m_sys;}
|
||||
inline const std::string& sys_str() const {return m_sys;}
|
||||
inline std::string operator+(const std::string& other) const {return m_sys + other;}
|
||||
inline std::string operator+(const char* other) const {return m_sys + other;}
|
||||
operator const std::string&() const {return m_sys;}
|
||||
const std::string& sys_str() const {return m_sys;}
|
||||
std::string operator+(const std::string& other) const {return m_sys + other;}
|
||||
std::string operator+(const char* other) const {return m_sys + other;}
|
||||
};
|
||||
inline std::string operator+(const std::string& lhs, const SystemStringView& rhs) {return lhs + std::string(rhs);}
|
||||
inline std::string operator+(const char* lhs, const SystemStringView& rhs) {return lhs + std::string(rhs);}
|
||||
|
@ -343,15 +343,15 @@ public:
|
|||
: num(*(uint32_t*)name) {}
|
||||
FourCC(uint32_t n)
|
||||
: num(n) {}
|
||||
inline bool operator==(const FourCC& other) const {return num == other.num;}
|
||||
inline bool operator!=(const FourCC& other) const {return num != other.num;}
|
||||
inline bool operator==(const char* other) const {return num == *(uint32_t*)other;}
|
||||
inline bool operator!=(const char* other) const {return num != *(uint32_t*)other;}
|
||||
inline bool operator==(uint32_t other) const {return num == other;}
|
||||
inline bool operator!=(uint32_t other) const {return num != other;}
|
||||
inline std::string toString() const {return std::string(fcc, 4);}
|
||||
inline uint32_t toUint32() const {return num;}
|
||||
inline operator uint32_t() const {return num;}
|
||||
bool operator==(const FourCC& other) const {return num == other.num;}
|
||||
bool operator!=(const FourCC& other) const {return num != other.num;}
|
||||
bool operator==(const char* other) const {return num == *(uint32_t*)other;}
|
||||
bool operator!=(const char* other) const {return num != *(uint32_t*)other;}
|
||||
bool operator==(uint32_t other) const {return num == other;}
|
||||
bool operator!=(uint32_t other) const {return num != other;}
|
||||
std::string toString() const {return std::string(fcc, 4);}
|
||||
uint32_t toUint32() const {return num;}
|
||||
operator uint32_t() const {return num;}
|
||||
};
|
||||
#define FOURCC(chars) FourCC(SBIG(chars))
|
||||
|
||||
|
@ -363,25 +363,25 @@ public:
|
|||
*/
|
||||
class Hash final
|
||||
{
|
||||
int64_t hash;
|
||||
unsigned long long hash;
|
||||
public:
|
||||
Hash(const void* buf, size_t len)
|
||||
: hash(Blowfish_hash((uint8_t*)buf, len)) {}
|
||||
: hash(XXH64((uint8_t*)buf, len, 0)) {}
|
||||
Hash(const std::string& str)
|
||||
: hash(Blowfish_hash((uint8_t*)str.data(), str.size())) {}
|
||||
: hash(XXH64((uint8_t*)str.data(), str.size(), 0)) {}
|
||||
Hash(const std::wstring& str)
|
||||
: hash(Blowfish_hash((uint8_t*)str.data(), str.size()*2)) {}
|
||||
Hash(int64_t hashin)
|
||||
: hash(XXH64((uint8_t*)str.data(), str.size()*2, 0)) {}
|
||||
Hash(unsigned long long hashin)
|
||||
: hash(hashin) {}
|
||||
Hash(const Hash& other) {hash = other.hash;}
|
||||
inline size_t val() const {return hash;}
|
||||
inline Hash& operator=(const Hash& other) {hash = other.hash; return *this;}
|
||||
inline bool operator==(const Hash& other) const {return hash == other.hash;}
|
||||
inline bool operator!=(const Hash& other) const {return hash != other.hash;}
|
||||
inline bool operator<(const Hash& other) const {return hash < other.hash;}
|
||||
inline bool operator>(const Hash& other) const {return hash > other.hash;}
|
||||
inline bool operator<=(const Hash& other) const {return hash <= other.hash;}
|
||||
inline bool operator>=(const Hash& other) const {return hash >= other.hash;}
|
||||
unsigned long long val() const {return hash;}
|
||||
Hash& operator=(const Hash& other) {hash = other.hash; return *this;}
|
||||
bool operator==(const Hash& other) const {return hash == other.hash;}
|
||||
bool operator!=(const Hash& other) const {return hash != other.hash;}
|
||||
bool operator<(const Hash& other) const {return hash < other.hash;}
|
||||
bool operator>(const Hash& other) const {return hash > other.hash;}
|
||||
bool operator<=(const Hash& other) const {return hash <= other.hash;}
|
||||
bool operator>=(const Hash& other) const {return hash >= other.hash;}
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -394,14 +394,14 @@ public:
|
|||
Time() : ts(time(NULL)) {}
|
||||
Time(time_t ti) : ts(ti) {}
|
||||
Time(const Time& other) {ts = other.ts;}
|
||||
inline time_t getTs() const {return ts;}
|
||||
inline Time& operator=(const Time& other) {ts = other.ts; return *this;}
|
||||
inline bool operator==(const Time& other) const {return ts == other.ts;}
|
||||
inline bool operator!=(const Time& other) const {return ts != other.ts;}
|
||||
inline bool operator<(const Time& other) const {return ts < other.ts;}
|
||||
inline bool operator>(const Time& other) const {return ts > other.ts;}
|
||||
inline bool operator<=(const Time& other) const {return ts <= other.ts;}
|
||||
inline bool operator>=(const Time& other) const {return ts >= other.ts;}
|
||||
time_t getTs() const {return ts;}
|
||||
Time& operator=(const Time& other) {ts = other.ts; return *this;}
|
||||
bool operator==(const Time& other) const {return ts == other.ts;}
|
||||
bool operator!=(const Time& other) const {return ts != other.ts;}
|
||||
bool operator<(const Time& other) const {return ts < other.ts;}
|
||||
bool operator>(const Time& other) const {return ts > other.ts;}
|
||||
bool operator<=(const Time& other) const {return ts <= other.ts;}
|
||||
bool operator>=(const Time& other) const {return ts >= other.ts;}
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -470,14 +470,14 @@ public:
|
|||
* @brief Determine if ProjectPath represents project root directory
|
||||
* @return true if project root directory
|
||||
*/
|
||||
inline bool isRoot() const {return m_relPath.empty();}
|
||||
bool isRoot() const {return m_relPath.empty();}
|
||||
|
||||
/**
|
||||
* @brief Return new ProjectPath with extension added
|
||||
* @param ext file extension to add
|
||||
* @return new path with extension
|
||||
*/
|
||||
inline ProjectPath getWithExtension(const SystemChar* ext) const
|
||||
ProjectPath getWithExtension(const SystemChar* ext) const
|
||||
{
|
||||
ProjectPath pp(*this);
|
||||
pp.m_relPath += ext;
|
||||
|
@ -489,13 +489,13 @@ public:
|
|||
* @brief Access fully-canonicalized absolute path
|
||||
* @return Absolute path reference
|
||||
*/
|
||||
inline const SystemString& getAbsolutePath() const {return m_absPath;}
|
||||
const SystemString& getAbsolutePath() const {return m_absPath;}
|
||||
|
||||
/**
|
||||
* @brief Access fully-canonicalized project-relative path
|
||||
* @return Relative pointer to within absolute-path or "." for project root-directory (use isRoot to detect)
|
||||
*/
|
||||
inline const SystemString& getRelativePath() const
|
||||
const SystemString& getRelativePath() const
|
||||
{
|
||||
if (m_relPath.size())
|
||||
return m_relPath;
|
||||
|
@ -507,7 +507,7 @@ public:
|
|||
* @brief Access fully-canonicalized absolute path in UTF-8
|
||||
* @return Absolute path reference
|
||||
*/
|
||||
inline const std::string& getAbsolutePathUTF8() const
|
||||
const std::string& getAbsolutePathUTF8() const
|
||||
{
|
||||
#if HECL_UCS2
|
||||
return m_utf8AbsPath;
|
||||
|
@ -516,7 +516,7 @@ public:
|
|||
#endif
|
||||
}
|
||||
|
||||
inline const std::string& getRelativePathUTF8() const
|
||||
const std::string& getRelativePathUTF8() const
|
||||
{
|
||||
#if HECL_UCS2
|
||||
return m_utf8RelPath;
|
||||
|
@ -562,7 +562,7 @@ public:
|
|||
* @brief Count how many directory levels deep in project path is
|
||||
* @return Level Count
|
||||
*/
|
||||
inline size_t levelCount() const
|
||||
size_t levelCount() const
|
||||
{
|
||||
size_t count = 0;
|
||||
for (SystemChar ch : m_relPath)
|
||||
|
@ -577,13 +577,13 @@ public:
|
|||
* Fatal log report is issued if directory is not able to be created or doesn't already exist.
|
||||
* If directory already exists, no action taken.
|
||||
*/
|
||||
inline void makeDir() const {MakeDir(m_absPath.c_str());}
|
||||
void makeDir() const {MakeDir(m_absPath.c_str());}
|
||||
|
||||
/**
|
||||
* @brief Create relative symbolic link at calling path targeting another path
|
||||
* @param target Path to target
|
||||
*/
|
||||
inline void makeLinkTo(const ProjectPath& target) const
|
||||
void makeLinkTo(const ProjectPath& target) const
|
||||
{
|
||||
SystemString relTarget;
|
||||
for (SystemChar ch : m_relPath)
|
||||
|
@ -596,9 +596,9 @@ public:
|
|||
* @brief HECL-specific blowfish hash
|
||||
* @return unique hash value
|
||||
*/
|
||||
inline size_t hash() const {return m_hash.val();}
|
||||
inline bool operator==(const ProjectPath& other) const {return m_hash == other.m_hash;}
|
||||
inline bool operator!=(const ProjectPath& other) const {return m_hash != other.m_hash;}
|
||||
size_t hash() const {return m_hash.val();}
|
||||
bool operator==(const ProjectPath& other) const {return m_hash == other.m_hash;}
|
||||
bool operator!=(const ProjectPath& other) const {return m_hash != other.m_hash;}
|
||||
|
||||
};
|
||||
|
||||
|
@ -721,12 +721,12 @@ namespace std
|
|||
{
|
||||
template <> struct hash<HECL::FourCC>
|
||||
{
|
||||
inline size_t operator()(const HECL::FourCC& val) const NOEXCEPT
|
||||
size_t operator()(const HECL::FourCC& val) const NOEXCEPT
|
||||
{return val.toUint32();}
|
||||
};
|
||||
template <> struct hash<HECL::ProjectPath>
|
||||
{
|
||||
inline size_t operator()(const HECL::ProjectPath& val) const NOEXCEPT
|
||||
size_t operator()(const HECL::ProjectPath& val) const NOEXCEPT
|
||||
{return val.hash();}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue