60 namespace Murmur3Implementation
99 inline uint32_t
rotl32 ( uint32_t
x, int8_t r )
101 return (
x << r) | (
x >> (32 - r));
111 inline uint64_t
rotl64 ( uint64_t
x, int8_t r )
113 return (
x << r) | (
x >> (64 - r));
117 #define BIG_CONSTANT(x) (x##LLU)
130 inline uint32_t
getblock (
const uint32_t * p, std::size_t i )
135 inline uint64_t
getblock (
const uint64_t * p, std::size_t i )
147 inline uint32_t
fmix ( uint32_t h )
160 inline uint64_t
fmix ( uint64_t h )
183 uint32_t seed,
void * out );
192 uint32_t seed,
void * out );
197 uint32_t seed,
void * out )
205 uint32_t seed,
void * out )
207 const uint8_t *
data = (
const uint8_t*)key;
208 const std::size_t nblocks = len / 4;
212 uint32_t c1 = 0xcc9e2d51;
213 uint32_t c2 = 0x1b873593;
219 const uint32_t * blocks = (
const uint32_t *)(
data);
222 for(std::size_t i = 0; i < nblocks; i++)
232 h1 = h1*5+0xe6546b64;
238 const uint8_t * tail = (
const uint8_t*)(
data + nblocks*4);
244 case 3: k1 ^= tail[2] << 16;
245 case 2: k1 ^= tail[1] << 8;
246 case 1: k1 ^= tail[0];
247 k1 *= c1; k1 =
rotl32(k1,15); k1 *= c2; h1 ^= k1;
250 *(uint32_t *)out = h1;
255 uint32_t seed,
void * out )
266 *(uint32_t *)out = h1;
281 uint32_t * seeds,
void * out );
290 uint32_t * seeds,
void * out );
302 uint32_t seed,
void * out )
306 seeds[0] = seeds[1] = seeds[2] = seeds[3] = seed;
312 uint32_t * seeds,
void * out )
314 const uint8_t *
data = (
const uint8_t*)key;
315 const std::size_t nblocks = len / 16;
317 uint32_t h1 = seeds[0];
318 uint32_t h2 = seeds[1];
319 uint32_t h3 = seeds[2];
320 uint32_t h4 = seeds[3];
322 uint32_t c1 = 0x239b961b;
323 uint32_t c2 = 0xab0e9789;
324 uint32_t c3 = 0x38b34ae5;
325 uint32_t c4 = 0xa1e38b93;
331 const uint32_t * blocks = (
const uint32_t *)(
data);
334 for(std::size_t i = 0; i < nblocks; i++)
336 uint32_t k1 =
getblock(blocks,i*4+0);
337 uint32_t k2 =
getblock(blocks,i*4+1);
338 uint32_t k3 =
getblock(blocks,i*4+2);
339 uint32_t k4 =
getblock(blocks,i*4+3);
341 k1 *= c1; k1 =
rotl32(k1,15); k1 *= c2; h1 ^= k1;
343 h1 =
rotl32(h1,19); h1 += h2; h1 = h1*5+0x561ccd1b;
345 k2 *= c2; k2 =
rotl32(k2,16); k2 *= c3; h2 ^= k2;
347 h2 =
rotl32(h2,17); h2 += h3; h2 = h2*5+0x0bcaa747;
349 k3 *= c3; k3 =
rotl32(k3,17); k3 *= c4; h3 ^= k3;
351 h3 =
rotl32(h3,15); h3 += h4; h3 = h3*5+0x96cd1c35;
353 k4 *= c4; k4 =
rotl32(k4,18); k4 *= c1; h4 ^= k4;
355 h4 =
rotl32(h4,13); h4 += h1; h4 = h4*5+0x32ac3b17;
361 const uint8_t * tail = (
const uint8_t*)(
data + nblocks*16);
370 case 15: k4 ^= tail[14] << 16;
371 case 14: k4 ^= tail[13] << 8;
372 case 13: k4 ^= tail[12] << 0;
373 k4 *= c4; k4 =
rotl32(k4,18); k4 *= c1; h4 ^= k4;
375 case 12: k3 ^= tail[11] << 24;
376 case 11: k3 ^= tail[10] << 16;
377 case 10: k3 ^= tail[ 9] << 8;
378 case 9: k3 ^= tail[ 8] << 0;
379 k3 *= c3; k3 =
rotl32(k3,17); k3 *= c4; h3 ^= k3;
381 case 8: k2 ^= tail[ 7] << 24;
382 case 7: k2 ^= tail[ 6] << 16;
383 case 6: k2 ^= tail[ 5] << 8;
384 case 5: k2 ^= tail[ 4] << 0;
385 k2 *= c2; k2 =
rotl32(k2,16); k2 *= c3; h2 ^= k2;
387 case 4: k1 ^= tail[ 3] << 24;
388 case 3: k1 ^= tail[ 2] << 16;
389 case 2: k1 ^= tail[ 1] << 8;
390 case 1: k1 ^= tail[ 0] << 0;
391 k1 *= c1; k1 =
rotl32(k1,15); k1 *= c2; h1 ^= k1;
394 ((uint32_t *)out)[0] = h1;
395 ((uint32_t *)out)[1] = h2;
396 ((uint32_t *)out)[2] = h3;
397 ((uint32_t *)out)[3] = h4;
402 uint32_t * seeds,
void * out )
407 uint32_t h1 = seeds[0];
408 uint32_t h2 = seeds[1];
409 uint32_t h3 = seeds[2];
410 uint32_t h4 = seeds[3];
412 h1 ^= len; h2 ^= len; h3 ^= len; h4 ^= len;
414 h1 += h2; h1 += h3; h1 += h4;
415 h2 += h1; h3 += h1; h4 += h1;
422 h1 += h2; h1 += h3; h1 += h4;
423 h2 += h1; h3 += h1; h4 += h1;
425 ((uint32_t *)out)[0] = h1;
426 ((uint32_t *)out)[1] = h2;
427 ((uint32_t *)out)[2] = h3;
428 ((uint32_t *)out)[3] = h4;
434 const uint32_t seed,
void * out )
436 const uint8_t *
data = (
const uint8_t*)key;
437 const std::size_t nblocks = len / 16;
448 const uint64_t * blocks = (
const uint64_t *)(
data);
450 for(std::size_t i = 0; i < nblocks; i++)
452 uint64_t k1 =
getblock(blocks,i*2+0);
453 uint64_t k2 =
getblock(blocks,i*2+1);
455 k1 *= c1; k1 =
rotl64(k1,31); k1 *= c2; h1 ^= k1;
457 h1 =
rotl64(h1,27); h1 += h2; h1 = h1*5+0x52dce729;
459 k2 *= c2; k2 =
rotl64(k2,33); k2 *= c1; h2 ^= k2;
461 h2 =
rotl64(h2,31); h2 += h1; h2 = h2*5+0x38495ab5;
467 const uint8_t * tail = (
const uint8_t*)(
data + nblocks*16);
474 case 15: k2 ^= uint64_t(tail[14]) << 48;
475 case 14: k2 ^= uint64_t(tail[13]) << 40;
476 case 13: k2 ^= uint64_t(tail[12]) << 32;
477 case 12: k2 ^= uint64_t(tail[11]) << 24;
478 case 11: k2 ^= uint64_t(tail[10]) << 16;
479 case 10: k2 ^= uint64_t(tail[ 9]) << 8;
480 case 9: k2 ^= uint64_t(tail[ 8]) << 0;
481 k2 *= c2; k2 =
rotl64(k2,33); k2 *= c1; h2 ^= k2;
483 case 8: k1 ^= uint64_t(tail[ 7]) << 56;
484 case 7: k1 ^= uint64_t(tail[ 6]) << 48;
485 case 6: k1 ^= uint64_t(tail[ 5]) << 40;
486 case 5: k1 ^= uint64_t(tail[ 4]) << 32;
487 case 4: k1 ^= uint64_t(tail[ 3]) << 24;
488 case 3: k1 ^= uint64_t(tail[ 2]) << 16;
489 case 2: k1 ^= uint64_t(tail[ 1]) << 8;
490 case 1: k1 ^= uint64_t(tail[ 0]) << 0;
491 k1 *= c1; k1 =
rotl64(k1,31); k1 *= c2; h1 ^= k1;
497 h1 ^= len; h2 ^= len;
508 ((uint32_t *)out)[0] =
static_cast<uint32_t
> (h1);
509 ((uint32_t *)out)[1] =
static_cast<uint32_t
> (h2);
531 using namespace Murmur3Implementation;
534 m_size32 +=
static_cast<uint32_t
>(size);
544 using namespace Murmur3Implementation;
564 uint64_t result =
hash[1];
565 result = (result << 32) |
hash[0];
void clear() override
Restore initial state.
Murmur3()
Constructor, clears internal state.
std::size_t m_size32
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 std::size_t size) override
Compute 32-bit hash of a byte buffer.
uint32_t m_hash32
Cache last hash value, and total bytes hashed (needed to finalize), for incremental hashing.
static constexpr auto SEED
Seed value.
uint64_t GetHash64(const char *buffer, const std::size_t size) override
Compute 64-bit hash of a byte buffer.
std::size_t m_size64
murmur3 produces 128-bit hash and state; we use just the first 64-bits.
void MurmurHash3_x86_128_fin(const std::size_t len, uint32_t *seeds, void *out)
Finalize a hash.
void MurmurHash3_x86_128_incr(const void *key, const std::size_t len, uint32_t *seeds, void *out)
Initial and incremental hash.
uint32_t getblock(const uint32_t *p, std::size_t i)
Block read.
uint64_t rotl64(uint64_t x, int8_t r)
Barrel shift (rotate) left on 64 bits.
uint32_t fmix(uint32_t h)
Finalization mix - force all bits of a hash block to avalanche.
uint32_t rotl32(uint32_t x, int8_t r)
Barrel shift (rotate) left on 32 bits.
void MurmurHash3_x64_128(const void *key, const std::size_t len, const uint32_t seed, void *out)
Initial and incremental hash.
void MurmurHash3_x86_32(const void *key, std::size_t len, uint32_t seed, void *out)
Initial and incremental hash.
void MurmurHash3_x86_128(const void *key, const std::size_t len, uint32_t seed, void *out)
Initial and incremental hash.
void MurmurHash3_x86_32_fin(std::size_t len, uint32_t seed, void *out)
Finalize a hash.
void MurmurHash3_x86_32_incr(const void *key, std::size_t len, uint32_t seed, void *out)
Initial and incremental hash.
#define BIG_CONSTANT(x)
Unsigned long long constants.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
ns3::Hash::Function::Murmur3 declaration.
std::size_t hash(const BasicJsonType &j)
hash a JSON value
Every class exported by the ns3 library is enclosed in the ns3 namespace.