X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libhashkit%2Fhsieh.c;h=cb5af8aec74524540fd97afb2b1bac0ffd797c07;hb=dac169cdb8e544f5967bb8d22f229b49d78afa9a;hp=cd44b67ff5c86993033664d2443e309cdc025779;hpb=dec0636927f5d0ae4cf06ad2710d022990419879;p=awesomized%2Flibmemcached diff --git a/libhashkit/hsieh.c b/libhashkit/hsieh.c index cd44b67f..cb5af8ae 100644 --- a/libhashkit/hsieh.c +++ b/libhashkit/hsieh.c @@ -1,11 +1,11 @@ /* By Paul Hsieh (C) 2004, 2005. Covered under the Paul Hsieh - * derivative license. + * derivative license. * See: http://www.azillionmonkeys.com/qed/weblicense.html for license * details. * http://www.azillionmonkeys.com/qed/hash.html */ -#include "hash_common.h" +#include "common.h" #undef get16bits #if (defined(__GNUC__) && defined(__i386__)) @@ -17,13 +17,13 @@ +(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; if (key_length <= 0 || key == NULL) - return 0; + return EXIT_SUCCESS; rem = key_length & 3; key_length >>= 2; @@ -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 */