X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libhashkit%2Fhsieh.c;h=35a2e2096c23d5c2f300a9ca877b095cc45aaabd;hb=32837dc24fd35afdc5855b3a7540270991b17611;hp=9060bba030e2f40441f91f58446fb59e38227443;hpb=e42302e08fa4d04cb21eaf7493f5f92b11169c03;p=m6w6%2Flibmemcached diff --git a/libhashkit/hsieh.c b/libhashkit/hsieh.c index 9060bba0..35a2e209 100644 --- a/libhashkit/hsieh.c +++ b/libhashkit/hsieh.c @@ -5,7 +5,7 @@ * http://www.azillionmonkeys.com/qed/hash.html */ -#include "common.h" +#include #undef get16bits #if (defined(__GNUC__) && defined(__i386__)) @@ -17,7 +17,7 @@ +(uint32_t)(((const uint8_t *)(d))[0]) ) #endif -uint32_t hashkit_hsieh(const char *key, size_t key_length) +uint32_t hashkit_hsieh(const char *key, size_t key_length, void *context __attribute__((unused))) { uint32_t hash = 0, tmp; int rem; @@ -43,16 +43,18 @@ uint32_t hashkit_hsieh(const char *key, size_t key_length) { case 3: hash += get16bits (key); hash ^= hash << 16; - hash ^= key[sizeof (uint16_t)] << 18; + hash ^= (uint32_t)key[sizeof (uint16_t)] << 18; hash += hash >> 11; break; case 2: hash += get16bits (key); hash ^= hash << 11; hash += hash >> 17; break; - case 1: hash += *key; + case 1: hash += (unsigned char)(*key); hash ^= hash << 10; hash += hash >> 1; + default: + break; } /* Force "avalanching" of final 127 bits */