40 memcpy(&result, p,
sizeof(result));
46 memcpy(&result, p,
sizeof(result));
53 #define bswap_32(x) _byteswap_ulong(x) 54 #define bswap_64(x) _byteswap_uint64(x) 56 #elif defined(__APPLE__) 59 #include <libkern/OSByteOrder.h> 60 #define bswap_32(x) OSSwapInt32(x) 61 #define bswap_64(x) OSSwapInt64(x) 63 #elif defined(__NetBSD__) 65 #include <sys/types.h> 66 #include <machine/bswap.h> 67 #if defined(__BSWAP_RENAME) && !defined(__bswap_32) 68 #define bswap_32(x) bswap32(x) 69 #define bswap_64(x) bswap64(x) 73 #elif defined(__FreeBSD__) 77 #include <sys/types.h> 78 #include <sys/endian.h> 79 #define bswap_16(x) bswap16(x) 80 #define bswap_32(x) bswap32(x) 81 #define bswap_64(x) bswap64(x) 89 #ifdef WORDS_BIGENDIAN 90 #define uint32_in_expected_order(x) (bswap_32(x)) 91 #define uint64_in_expected_order(x) (bswap_64(x)) 93 #define uint32_in_expected_order(x) (x) 94 #define uint64_in_expected_order(x) (x) 98 #if HAVE_BUILTIN_EXPECT 99 #define LIKELY(x) (__builtin_expect(!!(x), 1)) 101 #define LIKELY(x) (x) 119 static const uint32_t
c1 = 0xcc9e2d51;
120 static const uint32_t
c2 = 0x1b873593;
135 return shift == 0 ? val : ((val >> shift) | (val << (32 - shift)));
139 #define PERMUTE3(a, b, c) do { std::swap(a, b); std::swap(a, c); } while (0) 148 return h * 5 + 0xe6546b64;
166 for (
size_t i = 0; i < len; i++) {
167 signed char v = s[i];
175 uint32 a = len, b = len * 5, c = 9, d = b;
178 c +=
Fetch32(s + ((len >> 1) & 4));
190 uint32 h = len, g =
c1 * len, f = g;
198 h = h * 5 + 0xe6546b64;
201 h = h * 5 + 0xe6546b64;
204 g = g * 5 + 0xe6546b64;
207 g = g * 5 + 0xe6546b64;
210 f = f * 5 + 0xe6546b64;
211 size_t iters = (len - 1) / 20;
220 h = h * 5 + 0xe6546b64;
226 g = g * 5 + 0xe6546b64;
229 h = h * 5 + 0xe6546b64;
237 }
while (--iters != 0);
243 h = h * 5 + 0xe6546b64;
246 h = h * 5 + 0xe6546b64;
255 return shift == 0 ? val : ((val >> shift) | (val << (64 - shift)));
259 return val ^ (val >> 47);
292 uint8 b = s[len >> 1];
293 uint8 c = s[len - 1];
294 uint32 y =
static_cast<uint32>(a) + (static_cast<uint32>(b) << 8);
318 b =
Rotate(b + a + z, 21);
323 return make_pair(a + z, b + c);
349 uint64 v = ((a + g) ^ d) + f + 1;
350 uint64 w = bswap_64((u + v) * mul) + h;
352 uint64 y = (bswap_64((v + w) * mul) + g) * mul;
354 a = bswap_64((x + z) * mul + y) + b;
355 b =
ShiftMix((z + a) * mul + d + h) * mul;
366 }
else if (len <= 64) {
380 len = (len - 1) & ~static_cast<size_t>(63);
382 x =
Rotate(x + y + v.first + Fetch64(s + 8), 37) *
k1;
383 y =
Rotate(y + v.second + Fetch64(s + 48), 42) *
k1;
385 y += v.first +
Fetch64(s + 40);
413 signed long l = len - 16;
445 pair<uint64, uint64> v, w;
451 w.first =
Rotate(y + z, 35) * k1 + x;
456 x =
Rotate(x + y + v.first + Fetch64(s + 8), 37) *
k1;
457 y =
Rotate(y + v.second + Fetch64(s + 48), 42) *
k1;
459 y += v.first +
Fetch64(s + 40);
465 x =
Rotate(x + y + v.first + Fetch64(s + 8), 37) *
k1;
466 y =
Rotate(y + v.second + Fetch64(s + 48), 42) *
k1;
468 y += v.first +
Fetch64(s + 40);
475 }
while (
LIKELY(len >= 128));
482 for (
size_t tail_done = 0; tail_done < len; ) {
484 y =
Rotate(x + y, 42) *
k0 + v.second;
485 w.first +=
Fetch64(s + len - tail_done + 16);
486 x = x *
k0 + w.first;
487 z += w.second +
Fetch64(s + len - tail_done);
static uint32 Fetch32(const char *p)
void swap(any &x, any &y) any_noexcept
static uint32 Mur(uint32 a, uint32 h)
std::pair< uint64, uint64 > uint128
static uint32 fmix(uint32 h)
uint64 Hash128to64(const uint128 &x)
static uint32 Rotate32(uint32 val, int shift)
uint64 CityHash64WithSeeds(const char *s, size_t len, uint64 seed0, uint64 seed1)
uint32 CityHash32(const char *s, size_t len)
static pair< uint64, uint64 > WeakHashLen32WithSeeds(uint64 w, uint64 x, uint64 y, uint64 z, uint64 a, uint64 b)
static uint64 UNALIGNED_LOAD64(const char *p)
uint64 Uint128High64(const uint128 &x)
static uint32 Hash32Len0to4(const char *s, size_t len)
uint64 CityHash64(const char *s, size_t len)
static uint32 Hash32Len13to24(const char *s, size_t len)
static uint128 CityMurmur(const char *s, size_t len, uint128 seed)
static uint32 Hash32Len5to12(const char *s, size_t len)
#define uint32_in_expected_order(x)
static uint32 UNALIGNED_LOAD32(const char *p)
uint64 CityHash64WithSeed(const char *s, size_t len, uint64 seed)
uint64 Uint128Low64(const uint128 &x)
static uint64 Rotate(uint64 val, int shift)
static uint64 HashLen17to32(const char *s, size_t len)
uint128 CityHash128(const char *s, size_t len)
uint128 CityHash128WithSeed(const char *s, size_t len, uint128 seed)
#define PERMUTE3(a, b, c)
static uint64 ShiftMix(uint64 val)
static uint64 Fetch64(const char *p)
static uint64 HashLen33to64(const char *s, size_t len)
#define uint64_in_expected_order(x)
static uint64 HashLen0to16(const char *s, size_t len)
static uint64 HashLen16(uint64 u, uint64 v)