33 namespace hash_internal {
35 #ifdef ABSL_IS_BIG_ENDIAN 36 #define uint32_in_expected_order(x) (absl::gbswap_32(x)) 37 #define uint64_in_expected_order(x) (absl::gbswap_64(x)) 39 #define uint32_in_expected_order(x) (x) 40 #define uint64_in_expected_order(x) (x) 52 static const uint64_t
k0 = 0xc3a5c85c97cb3127ULL;
53 static const uint64_t
k1 = 0xb492b66fbe98f273ULL;
54 static const uint64_t
k2 = 0x9ae16a3b2f90404fULL;
57 static const uint32_t
c1 = 0xcc9e2d51;
58 static const uint32_t
c2 = 0x1b873593;
61 static uint32_t
fmix(uint32_t h) {
70 static uint32_t
Rotate32(uint32_t val,
int shift) {
72 return shift == 0 ? val : ((val >> shift) | (val << (32 - shift)));
76 #define PERMUTE3(a, b, c) \ 82 static uint32_t
Mur(uint32_t
a, uint32_t h) {
89 return h * 5 + 0xe6546b64;
93 uint32_t
a =
Fetch32(s - 4 + (len >> 1));
95 uint32_t c =
Fetch32(s + len - 8);
96 uint32_t d =
Fetch32(s + (len >> 1));
98 uint32_t f =
Fetch32(s + len - 4);
107 for (
size_t i = 0;
i <
len;
i++) {
108 signed char v = s[
i];
116 uint32_t
a =
len,
b = len * 5, c = 9, d =
b;
119 c +=
Fetch32(s + ((len >> 1) & 4));
131 uint32_t h =
len, g = c1 *
len, f = g;
140 h = h * 5 + 0xe6546b64;
143 h = h * 5 + 0xe6546b64;
146 g = g * 5 + 0xe6546b64;
149 g = g * 5 + 0xe6546b64;
152 f = f * 5 + 0xe6546b64;
153 size_t iters = (len - 1) / 20;
162 h = h * 5 + 0xe6546b64;
168 g = g * 5 + 0xe6546b64;
171 h = h * 5 + 0xe6546b64;
179 }
while (--iters != 0);
185 h = h * 5 + 0xe6546b64;
188 h = h * 5 + 0xe6546b64;
195 static uint64_t
Rotate(uint64_t val,
int shift) {
197 return shift == 0 ? val : ((val >> shift) | (val << (64 - shift)));
200 static uint64_t
ShiftMix(uint64_t val) {
return val ^ (val >> 47); }
206 static uint64_t
HashLen16(uint64_t u, uint64_t
v, uint64_t mul) {
208 uint64_t
a = (u ^
v) * mul;
210 uint64_t
b = (v ^
a) * mul;
218 uint64_t mul = k2 + len * 2;
221 uint64_t c =
Rotate(b, 37) * mul +
a;
222 uint64_t d = (
Rotate(a, 25) +
b) * mul;
226 uint64_t mul = k2 + len * 2;
232 uint8_t
b = s[len >> 1];
233 uint8_t c = s[len - 1];
234 uint32_t y =
static_cast<uint32_t
>(
a) + (static_cast<uint32_t>(b) << 8);
235 uint32_t z = len + (
static_cast<uint32_t
>(c) << 2);
244 uint64_t mul = k2 + len * 2;
247 uint64_t c =
Fetch64(s + len - 8) * mul;
250 a +
Rotate(b + k2, 18) + c, mul);
256 uint64_t y, uint64_t z,
257 uint64_t
a, uint64_t
b) {
259 b =
Rotate(b + a + z, 21);
264 return std::make_pair(a + z, b + c);
276 uint64_t mul = k2 + len * 2;
279 uint64_t c =
Fetch64(s + len - 24);
280 uint64_t d =
Fetch64(s + len - 32);
282 uint64_t f =
Fetch64(s + 24) * 9;
283 uint64_t g =
Fetch64(s + len - 8);
284 uint64_t h =
Fetch64(s + len - 16) * mul;
285 uint64_t u =
Rotate(a + g, 43) + (
Rotate(b, 30) + c) * 9;
286 uint64_t
v = ((a + g) ^ d) + f + 1;
288 uint64_t x =
Rotate(e + f, 42) + c;
290 uint64_t z = e + f + c;
292 b =
ShiftMix((z + a) * mul + d + h) * mul;
303 }
else if (len <= 64) {
309 uint64_t x =
Fetch64(s + len - 40);
317 len = (len - 1) & ~static_cast<size_t>(63);
319 x =
Rotate(x + y + v.first + Fetch64(s + 8), 37) *
k1;
320 y =
Rotate(y + v.second + Fetch64(s + 48), 42) *
k1;
322 y += v.first +
Fetch64(s + 40);
static uint32_t fmix(uint32_t h)
uint64_t CityHash64WithSeed(const char *s, size_t len, uint64_t seed)
uint32_t CityHash32(const char *s, size_t len)
static uint64_t Fetch64(const char *p)
static uint64_t HashLen16(uint64_t u, uint64_t v)
uint64_t gbswap_64(uint64_t host_int)
#define PERMUTE3(a, b, c)
static uint32_t Hash32Len5to12(const char *s, size_t len)
static uint32_t Hash32Len0to4(const char *s, size_t len)
std::pair< uint64_t, uint64_t > uint128
#define uint64_in_expected_order(x)
static uint32_t Hash32Len13to24(const char *s, size_t len)
uint64_t CityHash64(const char *s, size_t len)
uint32_t gbswap_32(uint32_t host_int)
uint64_t CityHash64WithSeeds(const char *s, size_t len, uint64_t seed0, uint64_t seed1)
static std::pair< uint64_t, uint64_t > WeakHashLen32WithSeeds(uint64_t w, uint64_t x, uint64_t y, uint64_t z, uint64_t a, uint64_t b)
static uint64_t Rotate(uint64_t val, int shift)
static uint32_t Mur(uint32_t a, uint32_t h)
static uint64_t HashLen33to64(const char *s, size_t len)
void swap(absl::InlinedVector< T, N, A > &a, absl::InlinedVector< T, N, A > &b) noexcept(noexcept(a.swap(b)))
static uint32_t Fetch32(const char *p)
uint64_t Hash128to64(const uint128 &x)
#define uint32_in_expected_order(x)
static uint64_t ShiftMix(uint64_t val)
static uint64_t HashLen17to32(const char *s, size_t len)
static uint64_t HashLen0to16(const char *s, size_t len)
static uint32_t Rotate32(uint32_t val, int shift)