From: Date: Sat, 15 Mar 2008 20:24:40 +0000 (-0700) Subject: Update on murmur X-Git-Tag: _20~1^2~54 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=01de4afa83a6f906eb666ff23a0888fbb5f4005f;p=m6w6%2Flibmemcached Update on murmur --- diff --git a/libmemcached/murmur_hash.c b/libmemcached/murmur_hash.c index abb2deda..ce28ec38 100644 --- a/libmemcached/murmur_hash.c +++ b/libmemcached/murmur_hash.c @@ -2,47 +2,42 @@ /* "Murmur"hash provided by Austin, tanjent@gmail.com -#define MURMUR_POSTMIX */ +#define MIX(h,k,m) { k *= m; k ^= k >> r; k *= m; h *= m; h ^= k; } + uint32_t murmur_hash(char *key, size_t length) { - const unsigned int m= 0x7fd652ad; + const uint32_t m= 0x5bd1e995; const int r= 16; - - uint32_t h= 0xdeadbeef; + uint32_t h= length * m; while(length >= 4) { - h += *(unsigned int *)key; - h *= m; - h ^= h >> r; + uint32_t k = *(uint32_t*)key; + MIX(h,k,m); key += 4; length -= 4; } - switch(length) + if (length) { - case 3: - h += key[2] << 16; - case 2: - h += key[1] << 8; - case 1: - default: - h += key[0]; - h *= m; - h ^= h >> r; - }; - -#ifdef MURMUR_POSTMIX + uint32_t k= 0; + + switch(length) + { + case 3: k += key[2] << 16; + case 2: k += key[1] << 8; + case 1: k += key[0]; + }; + MIX(h,k,m); + } h *= m; h ^= h >> 10; h *= m; h ^= h >> 17; -#endif - return h; }