\r
/* \r
"Murmur"hash provided by Austin, tanjent@gmail.com\r
-#define MURMUR_POSTMIX\r
*/\r
\r
+#define MIX(h,k,m) { k *= m; k ^= k >> r; k *= m; h *= m; h ^= k; }\r
+\r
uint32_t murmur_hash(char *key, size_t length)\r
{\r
- const unsigned int m= 0x7fd652ad;\r
+ const uint32_t m= 0x5bd1e995;\r
const int r= 16;\r
-\r
- uint32_t h= 0xdeadbeef;\r
+ uint32_t h= length * m;\r
\r
while(length >= 4)\r
{\r
- h += *(unsigned int *)key;\r
- h *= m;\r
- h ^= h >> r;\r
+ uint32_t k = *(uint32_t*)key;\r
+ MIX(h,k,m);\r
\r
key += 4;\r
length -= 4;\r
}\r
\r
- switch(length)\r
+ if (length)\r
{\r
- case 3:\r
- h += key[2] << 16;\r
- case 2:\r
- h += key[1] << 8;\r
- case 1:\r
- default:\r
- h += key[0];\r
- h *= m;\r
- h ^= h >> r;\r
- };\r
-\r
-#ifdef MURMUR_POSTMIX\r
+ uint32_t k= 0;\r
+\r
+ switch(length)\r
+ {\r
+ case 3: k += key[2] << 16;\r
+ case 2: k += key[1] << 8;\r
+ case 1: k += key[0];\r
+ };\r
+ MIX(h,k,m);\r
+ }\r
\r
h *= m;\r
h ^= h >> 10;\r
h *= m;\r
h ^= h >> 17;\r
\r
-#endif\r
-\r
return h;\r
}\r