46 namespace Murmur3Implementation {
70 inline uint32_t
rotl32 ( uint32_t
x, int8_t r )
72 return (x << r) | (x >> (32 - r));
75 inline uint64_t
rotl64 ( uint64_t
x, int8_t r )
77 return (x << r) | (x >> (64 - r));
80 #define BIG_CONSTANT(x) (x##LLU)
86 inline uint32_t
getblock (
const uint32_t * p,
int i )
91 inline uint64_t
getblock (
const uint64_t * p,
int i )
99 inline uint32_t
fmix ( uint32_t h )
112 inline uint64_t
fmix ( uint64_t k )
127 uint32_t seed,
void * out );
129 uint32_t seed,
void * out );
133 uint32_t seed,
void * out )
141 uint32_t seed,
void * out )
143 const uint8_t *
data = (
const uint8_t*)key;
144 const int nblocks = len / 4;
148 uint32_t c1 = 0xcc9e2d51;
149 uint32_t c2 = 0x1b873593;
154 const uint32_t * blocks = (
const uint32_t *)(data + nblocks*4);
156 for(
int i = -nblocks; i; i++)
166 h1 = h1*5+0xe6546b64;
172 const uint8_t * tail = (
const uint8_t*)(data + nblocks*4);
178 case 3: k1 ^= tail[2] << 16;
179 case 2: k1 ^= tail[1] << 8;
180 case 1: k1 ^= tail[0];
181 k1 *= c1; k1 =
rotl32(k1,15); k1 *= c2; h1 ^= k1;
184 *(uint32_t *)out = h1;
189 uint32_t seed,
void * out )
200 *(uint32_t *)out = h1;
207 uint32_t * seeds,
void * out );
209 uint32_t * seeds,
void * out );
213 uint32_t seed,
void * out )
217 seeds[0] = seeds[1] = seeds[2] = seeds[3] = seed;
223 uint32_t * seeds,
void * out )
225 const uint8_t *
data = (
const uint8_t*)key;
226 const int nblocks = len / 16;
228 uint32_t h1 = seeds[0];
229 uint32_t h2 = seeds[1];
230 uint32_t h3 = seeds[2];
231 uint32_t h4 = seeds[3];
233 uint32_t c1 = 0x239b961b;
234 uint32_t c2 = 0xab0e9789;
235 uint32_t c3 = 0x38b34ae5;
236 uint32_t c4 = 0xa1e38b93;
241 const uint32_t * blocks = (
const uint32_t *)(data + nblocks*16);
243 for(
int i = -nblocks; i; i++)
245 uint32_t k1 =
getblock(blocks,i*4+0);
246 uint32_t k2 =
getblock(blocks,i*4+1);
247 uint32_t k3 =
getblock(blocks,i*4+2);
248 uint32_t k4 =
getblock(blocks,i*4+3);
250 k1 *= c1; k1 =
rotl32(k1,15); k1 *= c2; h1 ^= k1;
252 h1 =
rotl32(h1,19); h1 += h2; h1 = h1*5+0x561ccd1b;
254 k2 *= c2; k2 =
rotl32(k2,16); k2 *= c3; h2 ^= k2;
256 h2 =
rotl32(h2,17); h2 += h3; h2 = h2*5+0x0bcaa747;
258 k3 *= c3; k3 =
rotl32(k3,17); k3 *= c4; h3 ^= k3;
260 h3 =
rotl32(h3,15); h3 += h4; h3 = h3*5+0x96cd1c35;
262 k4 *= c4; k4 =
rotl32(k4,18); k4 *= c1; h4 ^= k4;
264 h4 =
rotl32(h4,13); h4 += h1; h4 = h4*5+0x32ac3b17;
270 const uint8_t * tail = (
const uint8_t*)(data + nblocks*16);
279 case 15: k4 ^= tail[14] << 16;
280 case 14: k4 ^= tail[13] << 8;
281 case 13: k4 ^= tail[12] << 0;
282 k4 *= c4; k4 =
rotl32(k4,18); k4 *= c1; h4 ^= k4;
284 case 12: k3 ^= tail[11] << 24;
285 case 11: k3 ^= tail[10] << 16;
286 case 10: k3 ^= tail[ 9] << 8;
287 case 9: k3 ^= tail[ 8] << 0;
288 k3 *= c3; k3 =
rotl32(k3,17); k3 *= c4; h3 ^= k3;
290 case 8: k2 ^= tail[ 7] << 24;
291 case 7: k2 ^= tail[ 6] << 16;
292 case 6: k2 ^= tail[ 5] << 8;
293 case 5: k2 ^= tail[ 4] << 0;
294 k2 *= c2; k2 =
rotl32(k2,16); k2 *= c3; h2 ^= k2;
296 case 4: k1 ^= tail[ 3] << 24;
297 case 3: k1 ^= tail[ 2] << 16;
298 case 2: k1 ^= tail[ 1] << 8;
299 case 1: k1 ^= tail[ 0] << 0;
300 k1 *= c1; k1 =
rotl32(k1,15); k1 *= c2; h1 ^= k1;
303 ((uint32_t *)out)[0] = h1;
304 ((uint32_t *)out)[1] = h2;
305 ((uint32_t *)out)[2] = h3;
306 ((uint32_t *)out)[3] = h4;
311 uint32_t * seeds,
void * out )
316 uint32_t h1 = seeds[0];
317 uint32_t h2 = seeds[1];
318 uint32_t h3 = seeds[2];
319 uint32_t h4 = seeds[3];
321 h1 ^= len; h2 ^= len; h3 ^= len; h4 ^= len;
323 h1 += h2; h1 += h3; h1 += h4;
324 h2 += h1; h3 += h1; h4 += h1;
331 h1 += h2; h1 += h3; h1 += h4;
332 h2 += h1; h3 += h1; h4 += h1;
334 ((uint32_t *)out)[0] = h1;
335 ((uint32_t *)out)[1] = h2;
336 ((uint32_t *)out)[2] = h3;
337 ((uint32_t *)out)[3] = h4;
343 const uint32_t seed,
void * out )
345 const uint8_t *
data = (
const uint8_t*)key;
346 const int nblocks = len / 16;
357 const uint64_t * blocks = (
const uint64_t *)(data);
359 for(
int i = 0; i < nblocks; i++)
361 uint64_t k1 =
getblock(blocks,i*2+0);
362 uint64_t k2 =
getblock(blocks,i*2+1);
364 k1 *= c1; k1 =
rotl64(k1,31); k1 *= c2; h1 ^= k1;
366 h1 =
rotl64(h1,27); h1 += h2; h1 = h1*5+0x52dce729;
368 k2 *= c2; k2 =
rotl64(k2,33); k2 *= c1; h2 ^= k2;
370 h2 =
rotl64(h2,31); h2 += h1; h2 = h2*5+0x38495ab5;
376 const uint8_t * tail = (
const uint8_t*)(data + nblocks*16);
383 case 15: k2 ^= uint64_t(tail[14]) << 48;
384 case 14: k2 ^= uint64_t(tail[13]) << 40;
385 case 13: k2 ^= uint64_t(tail[12]) << 32;
386 case 12: k2 ^= uint64_t(tail[11]) << 24;
387 case 11: k2 ^= uint64_t(tail[10]) << 16;
388 case 10: k2 ^= uint64_t(tail[ 9]) << 8;
389 case 9: k2 ^= uint64_t(tail[ 8]) << 0;
390 k2 *= c2; k2 =
rotl64(k2,33); k2 *= c1; h2 ^= k2;
392 case 8: k1 ^= uint64_t(tail[ 7]) << 56;
393 case 7: k1 ^= uint64_t(tail[ 6]) << 48;
394 case 6: k1 ^= uint64_t(tail[ 5]) << 40;
395 case 5: k1 ^= uint64_t(tail[ 4]) << 32;
396 case 4: k1 ^= uint64_t(tail[ 3]) << 24;
397 case 3: k1 ^= uint64_t(tail[ 2]) << 16;
398 case 2: k1 ^= uint64_t(tail[ 1]) << 8;
399 case 1: k1 ^= uint64_t(tail[ 0]) << 0;
400 k1 *= c1; k1 =
rotl64(k1,31); k1 *= c2; h1 ^= k1;
406 h1 ^= len; h2 ^= len;
417 ((uint32_t *)out)[0] = h1;
418 ((uint32_t *)out)[1] = h2;
441 using namespace Murmur3Implementation;
454 using namespace Murmur3Implementation;
474 (uint32_t *)(
void *)
m_hash64, hash);
475 uint64_t result = hash[1];
476 result = (result << 32) | hash[0];
uint32_t m_size32
Cache last hash value, and total bytes hashed (needed to finalize), for incremental hashing...
NS_LOG_COMPONENT_DEFINE("GrantedTimeWindowMpiInterface")
void MurmurHash3_x64_128(const void *key, const int len, const uint32_t seed, void *out)
virtual void clear(void)
Restore initial state.
uint64_t rotl64(uint64_t x, int8_t r)
void MurmurHash3_x86_32(const void *key, int len, uint32_t seed, void *out)
uint32_t fmix(uint32_t h)
uint32_t rotl32(uint32_t x, int8_t r)
void MurmurHash3_x86_32_incr(const void *key, int len, uint32_t seed, void *out)
void MurmurHash3_x86_128(const void *key, const int len, uint32_t seed, void *out)
Murmur3()
Constructor, clears internal state.
uint32_t getblock(const uint32_t *p, int i)
uint64_t m_size64
Cache last hash value, and total bytes hashed (needed to finalize), for incremental hashing...
uint64_t GetHash64(const char *buffer, const size_t size)
Compute 64-bit hash of a byte buffer.
void MurmurHash3_x86_32_fin(int len, uint32_t seed, void *out)
void MurmurHash3_x86_128_fin(const int len, uint32_t *seeds, void *out)
void MurmurHash3_x86_128_incr(const void *key, const int len, uint32_t *seeds, void *out)
uint32_t m_hash32
Cache last hash value, and total bytes hashed (needed to finalize), for incremental hashing...
uint64_t m_hash64[2]
murmur3 produces 128-bit hash and state; we use just the first 64-bits.
uint32_t GetHash32(const char *buffer, const size_t size)
Compute 32-bit hash of a byte buffer.