root/hash.c
/*DEFINITIONS
This source file includes following definitions.1 //----------------------------------------------------------------------------- 2 // MurmurHash2, 64-bit versions, by Austin Appleby 3 4 // The same caveats as 32-bit MurmurHash2 apply here - beware of alignment 5 // and endian-ness issues if used across multiple platforms. 6 7 #include "hash.h" 8 9 uint64_t mmh2a(const void *key, int len, unsigned int seed) { 10 const uint64_t m = 0xc6a4a7935bd1e995; 11 const int r = 47; 12 13 uint64_t h = seed ^ (len * m); 14 15 const uint64_t *data = (const uint64_t *)key; 16 const uint64_t *end = data + (len/8); 17 18 while(data != end) { 19 uint64_t k = *data++; 20 21 k *= m; 22 k ^= k >> r; 23 k *= m; 24 25 h ^= k; 26 h *= m; 27 } 28 29 const unsigned char *data2 = (const unsigned char*)data; 30 31 switch(len & 7) { 32 case 7: h ^= (uint64_t)data2[6] << 48; 33 case 6: h ^= (uint64_t)data2[5] << 40; 34 case 5: h ^= (uint64_t)data2[4] << 32; 35 case 4: h ^= (uint64_t)data2[3] << 24; 36 case 3: h ^= (uint64_t)data2[2] << 16; 37 case 2: h ^= (uint64_t)data2[1] << 8; 38 case 1: h ^= (uint64_t)data2[0]; 39 h *= m; 40 }; 41 42 h ^= h >> r; 43 h *= m; 44 h ^= h >> r; 45 46 return h;
/*