summaryrefslogtreecommitdiff
path: root/src/common/cityhash.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/cityhash.cpp')
-rw-r--r--src/common/cityhash.cpp22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/common/cityhash.cpp b/src/common/cityhash.cpp
index de31ffbd8..4e1d874b5 100644
--- a/src/common/cityhash.cpp
+++ b/src/common/cityhash.cpp
@@ -114,7 +114,7 @@ static uint64 HashLen16(uint64 u, uint64 v, uint64 mul) {
114 return b; 114 return b;
115} 115}
116 116
117static uint64 HashLen0to16(const char* s, size_t len) { 117static uint64 HashLen0to16(const char* s, std::size_t len) {
118 if (len >= 8) { 118 if (len >= 8) {
119 uint64 mul = k2 + len * 2; 119 uint64 mul = k2 + len * 2;
120 uint64 a = Fetch64(s) + k2; 120 uint64 a = Fetch64(s) + k2;
@@ -141,7 +141,7 @@ static uint64 HashLen0to16(const char* s, size_t len) {
141 141
142// This probably works well for 16-byte strings as well, but it may be overkill 142// This probably works well for 16-byte strings as well, but it may be overkill
143// in that case. 143// in that case.
144static uint64 HashLen17to32(const char* s, size_t len) { 144static uint64 HashLen17to32(const char* s, std::size_t len) {
145 uint64 mul = k2 + len * 2; 145 uint64 mul = k2 + len * 2;
146 uint64 a = Fetch64(s) * k1; 146 uint64 a = Fetch64(s) * k1;
147 uint64 b = Fetch64(s + 8); 147 uint64 b = Fetch64(s + 8);
@@ -170,7 +170,7 @@ static pair<uint64, uint64> WeakHashLen32WithSeeds(const char* s, uint64 a, uint
170} 170}
171 171
172// Return an 8-byte hash for 33 to 64 bytes. 172// Return an 8-byte hash for 33 to 64 bytes.
173static uint64 HashLen33to64(const char* s, size_t len) { 173static uint64 HashLen33to64(const char* s, std::size_t len) {
174 uint64 mul = k2 + len * 2; 174 uint64 mul = k2 + len * 2;
175 uint64 a = Fetch64(s) * k2; 175 uint64 a = Fetch64(s) * k2;
176 uint64 b = Fetch64(s + 8); 176 uint64 b = Fetch64(s + 8);
@@ -191,7 +191,7 @@ static uint64 HashLen33to64(const char* s, size_t len) {
191 return b + x; 191 return b + x;
192} 192}
193 193
194uint64 CityHash64(const char* s, size_t len) { 194uint64 CityHash64(const char* s, std::size_t len) {
195 if (len <= 32) { 195 if (len <= 32) {
196 if (len <= 16) { 196 if (len <= 16) {
197 return HashLen0to16(s, len); 197 return HashLen0to16(s, len);
@@ -212,7 +212,7 @@ uint64 CityHash64(const char* s, size_t len) {
212 x = x * k1 + Fetch64(s); 212 x = x * k1 + Fetch64(s);
213 213
214 // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks. 214 // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
215 len = (len - 1) & ~static_cast<size_t>(63); 215 len = (len - 1) & ~static_cast<std::size_t>(63);
216 do { 216 do {
217 x = Rotate(x + y + v.first + Fetch64(s + 8), 37) * k1; 217 x = Rotate(x + y + v.first + Fetch64(s + 8), 37) * k1;
218 y = Rotate(y + v.second + Fetch64(s + 48), 42) * k1; 218 y = Rotate(y + v.second + Fetch64(s + 48), 42) * k1;
@@ -229,17 +229,17 @@ uint64 CityHash64(const char* s, size_t len) {
229 HashLen16(v.second, w.second) + x); 229 HashLen16(v.second, w.second) + x);
230} 230}
231 231
232uint64 CityHash64WithSeed(const char* s, size_t len, uint64 seed) { 232uint64 CityHash64WithSeed(const char* s, std::size_t len, uint64 seed) {
233 return CityHash64WithSeeds(s, len, k2, seed); 233 return CityHash64WithSeeds(s, len, k2, seed);
234} 234}
235 235
236uint64 CityHash64WithSeeds(const char* s, size_t len, uint64 seed0, uint64 seed1) { 236uint64 CityHash64WithSeeds(const char* s, std::size_t len, uint64 seed0, uint64 seed1) {
237 return HashLen16(CityHash64(s, len) - seed0, seed1); 237 return HashLen16(CityHash64(s, len) - seed0, seed1);
238} 238}
239 239
240// A subroutine for CityHash128(). Returns a decent 128-bit hash for strings 240// A subroutine for CityHash128(). Returns a decent 128-bit hash for strings
241// of any length representable in signed long. Based on City and Murmur. 241// of any length representable in signed long. Based on City and Murmur.
242static uint128 CityMurmur(const char* s, size_t len, uint128 seed) { 242static uint128 CityMurmur(const char* s, std::size_t len, uint128 seed) {
243 uint64 a = Uint128Low64(seed); 243 uint64 a = Uint128Low64(seed);
244 uint64 b = Uint128High64(seed); 244 uint64 b = Uint128High64(seed);
245 uint64 c = 0; 245 uint64 c = 0;
@@ -269,7 +269,7 @@ static uint128 CityMurmur(const char* s, size_t len, uint128 seed) {
269 return uint128(a ^ b, HashLen16(b, a)); 269 return uint128(a ^ b, HashLen16(b, a));
270} 270}
271 271
272uint128 CityHash128WithSeed(const char* s, size_t len, uint128 seed) { 272uint128 CityHash128WithSeed(const char* s, std::size_t len, uint128 seed) {
273 if (len < 128) { 273 if (len < 128) {
274 return CityMurmur(s, len, seed); 274 return CityMurmur(s, len, seed);
275 } 275 }
@@ -313,7 +313,7 @@ uint128 CityHash128WithSeed(const char* s, size_t len, uint128 seed) {
313 w.first *= 9; 313 w.first *= 9;
314 v.first *= k0; 314 v.first *= k0;
315 // If 0 < len < 128, hash up to 4 chunks of 32 bytes each from the end of s. 315 // If 0 < len < 128, hash up to 4 chunks of 32 bytes each from the end of s.
316 for (size_t tail_done = 0; tail_done < len;) { 316 for (std::size_t tail_done = 0; tail_done < len;) {
317 tail_done += 32; 317 tail_done += 32;
318 y = Rotate(x + y, 42) * k0 + v.second; 318 y = Rotate(x + y, 42) * k0 + v.second;
319 w.first += Fetch64(s + len - tail_done + 16); 319 w.first += Fetch64(s + len - tail_done + 16);
@@ -331,7 +331,7 @@ uint128 CityHash128WithSeed(const char* s, size_t len, uint128 seed) {
331 return uint128(HashLen16(x + v.second, w.second) + y, HashLen16(x + w.second, y + v.second)); 331 return uint128(HashLen16(x + v.second, w.second) + y, HashLen16(x + w.second, y + v.second));
332} 332}
333 333
334uint128 CityHash128(const char* s, size_t len) { 334uint128 CityHash128(const char* s, std::size_t len) {
335 return len >= 16 335 return len >= 16
336 ? CityHash128WithSeed(s + 16, len - 16, uint128(Fetch64(s), Fetch64(s + 8) + k0)) 336 ? CityHash128WithSeed(s + 16, len - 16, uint128(Fetch64(s), Fetch64(s + 8) + k0))
337 : CityHash128WithSeed(s, len, uint128(k0, k1)); 337 : CityHash128WithSeed(s, len, uint128(k0, k1));