X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fhsieh_hash.c;h=91d515f216e767cccc97a1b5cecf6266ded601ba;hb=7b548d21a8eafec0b830ad1bd6429cecd4eaeba8;hp=9f42a94d02da91a6e62c2f8be1d1b762c3eb2892;hpb=1d7f999b7d38db3308a0533a83fea23987fb0178;p=awesomized%2Flibmemcached diff --git a/libmemcached/hsieh_hash.c b/libmemcached/hsieh_hash.c index 9f42a94d..91d515f2 100644 --- a/libmemcached/hsieh_hash.c +++ b/libmemcached/hsieh_hash.c @@ -17,18 +17,20 @@ +(uint32_t)(((const uint8_t *)(d))[0]) ) #endif -uint32_t hsieh_hash(char *key, size_t key_length) +uint32_t hsieh_hash(const char *key, size_t key_length) { uint32_t hash = 0, tmp; int rem; - if (key_length <= 0 || key == NULL) return 0; + if (key_length <= 0 || key == NULL) + return 0; rem = key_length & 3; key_length >>= 2; /* Main loop */ - for (;key_length > 0; key_length--) { + for (;key_length > 0; key_length--) + { hash += get16bits (key); tmp = (get16bits (key+2) << 11) ^ hash; hash = (hash << 16) ^ tmp; @@ -37,7 +39,8 @@ uint32_t hsieh_hash(char *key, size_t key_length) } /* Handle end cases */ - switch (rem) { + switch (rem) + { case 3: hash += get16bits (key); hash ^= hash << 16; hash ^= key[sizeof (uint16_t)] << 18;