33 #include <lal/LALHashFunc.h>
49 const UINT8 kMul = 0x9ddfea08eb382d69ULL;
60 memcpy(&result,
p,
sizeof(result));
66 memcpy(&result,
p,
sizeof(result));
70 #if defined(_WIN32) && !defined(__CYGWIN__)
73 #define bswap_32(x) _byteswap_ulong(x)
74 #define bswap_64(x) _byteswap_UINT8(x)
76 #elif defined(__APPLE__)
79 #include <libkern/OSByteOrder.h>
80 #define bswap_32(x) OSSwapInt32(x)
81 #define bswap_64(x) OSSwapInt64(x)
83 #elif defined(__sun) || defined(sun)
85 #include <sys/byteorder.h>
86 #define bswap_32(x) BSWAP_32(x)
87 #define bswap_64(x) BSWAP_64(x)
89 #elif defined(__FreeBSD__)
91 #include <sys/endian.h>
92 #define bswap_32(x) bswap32(x)
93 #define bswap_64(x) bswap64(x)
95 #elif defined(__OpenBSD__)
97 #include <sys/types.h>
98 #define bswap_32(x) swap32(x)
99 #define bswap_64(x) swap64(x)
101 #elif defined(__NetBSD__)
103 #include <sys/types.h>
104 #include <machine/bswap.h>
105 #if defined(__BSWAP_RENAME) && !defined(__bswap_32)
106 #define bswap_32(x) bswap32(x)
107 #define bswap_64(x) bswap64(x)
112 #include <byteswap.h>
116 #ifdef WORDS_BIGENDIAN
117 #define UINT4_in_expected_order(x) (bswap_32(x))
118 #define UINT8_in_expected_order(x) (bswap_64(x))
120 #define UINT4_in_expected_order(x) (x)
121 #define UINT8_in_expected_order(x) (x)
125 #if HAVE_BUILTIN_EXPECT
126 #define LIKELY(x) (__builtin_expect(!!(x), 1))
128 #define LIKELY(x) (x)
141 static const UINT8 k0 = 0xc3a5c85c97cb3127ULL;
142 static const UINT8 k1 = 0xb492b66fbe98f273ULL;
143 static const UINT8 k2 = 0x9ae16a3b2f90404fULL;
162 return shift == 0 ? val : ((val >> shift) | (val << (32 - shift)));
165 #define SWAP(a,b) {a^=b; b^=a; a^=b;}
168 #define PERMUTE3(a, b, c) do { SWAP(a, b); SWAP(a, c); } while (0)
177 return h * 5 + 0xe6546b64;
195 for (
size_t i = 0; i < len; i++) {
196 signed char v = s[i];
204 UINT4 a = len, b = len * 5, c = 9, d = b;
207 c +=
Fetch32(s + ((len >> 1) & 4));
227 h = h * 5 + 0xe6546b64;
230 h = h * 5 + 0xe6546b64;
233 g = g * 5 + 0xe6546b64;
236 g = g * 5 + 0xe6546b64;
239 f =
f * 5 + 0xe6546b64;
240 size_t iters = (len - 1) / 20;
249 h = h * 5 + 0xe6546b64;
255 g = g * 5 + 0xe6546b64;
258 h = h * 5 + 0xe6546b64;
266 }
while (--iters != 0);
272 h = h * 5 + 0xe6546b64;
275 h = h * 5 + 0xe6546b64;
284 return shift == 0 ? val : ((val >> shift) | (val << (64 - shift)));
288 return val ^ (val >> 47);
322 UCHAR b = s[len >> 1];
323 UCHAR c = s[len - 1];
379 UINT8 v = ((
a + g) ^ d) +
f + 1;
380 UINT8 w = bswap_64((u + v) * mul) + h;
382 UINT8 y = (bswap_64((v + w) * mul) + g) * mul;
384 a = bswap_64((
x + z) * mul +
y) + b;
385 b =
ShiftMix((z +
a) * mul + d + h) * mul;
396 }
else if (len <= 64) {
410 len = (len - 1) & ~((
size_t)63);
static UINT8 Uint128Low64(const UINT16 *x)
static UINT16 WeakHashLen32WithSeeds(const char *s, UINT8 a, UINT8 b)
static UINT4 UNALIGNED_LOAD32(const char *p)
static UINT16 WeakHashLen32WithSeeds_5(UINT8 w, UINT8 x, UINT8 y, UINT8 z, UINT8 a, UINT8 b)
static UINT8 Fetch64(const char *p)
static UINT8 Hash128to64(const UINT16 *x)
Hash 128 input bits down to 64 bits of output.
static UINT4 Hash32Len5to12(const char *s, size_t len)
static UINT8 HashLen16(UINT8 u, UINT8 v)
static UINT8 UNALIGNED_LOAD64(const char *p)
#define PERMUTE3(a, b, c)
static UINT4 Hash32Len13to24(const char *s, size_t len)
static UINT8 HashLen17to32(const char *s, size_t len)
static UINT8 HashLen33to64(const char *s, size_t len)
static UINT4 Mur(UINT4 a, UINT4 h)
static UINT4 Hash32Len0to4(const char *s, size_t len)
static UINT4 Fetch32(const char *p)
static UINT8 ShiftMix(UINT8 val)
static UINT8 Uint128High64(const UINT16 *x)
#define UINT4_in_expected_order(x)
static UINT8 HashLen0to16(const char *s, size_t len)
#define UINT8_in_expected_order(x)
static UINT4 fmix(UINT4 h)
static UINT4 Rotate32(UINT4 val, int shift)
static UINT8 Rotate(UINT8 val, int shift)
static UINT8 HashLen16mul(UINT8 u, UINT8 v, UINT8 mul)
static double f(double theta, double y, double xi)
unsigned char UCHAR
One-byte unsigned integer, see Headers LAL(Atomic)Datatypes.h for more details.
uint64_t UINT8
Eight-byte unsigned integer; on some platforms this is equivalent to unsigned long int instead.
uint32_t UINT4
Four-byte unsigned integer.
UINT8 XLALCityHash64WithSeeds(const char *s, size_t len, UINT8 seed0, UINT8 seed1)
Hash function for a byte array.
UINT8 XLALCityHash64(const char *s, size_t len)
Hash function for a byte array.
UINT4 XLALCityHash32(const char *s, size_t len)
Hash function for a byte array.
UINT8 XLALCityHash64WithSeed(const char *s, size_t len, UINT8 seed)
Hash function for a byte array.