579d0445b39fa65ebe9570c40e2dfc001778e27c
[awesomized/libmemcached] / libhashkit / one_at_a_time.c
1 /* HashKit
2 * Copyright (C) 2009 Brian Aker
3 * All rights reserved.
4 *
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
7 */
8
9 /*
10 This has is Jenkin's "One at A time Hash".
11 http://en.wikipedia.org/wiki/Jenkins_hash_function
12 */
13
14 #include "common.h"
15
16 uint32_t hashkit_one_at_a_time(const char *key, size_t key_length, void *context __attribute__((unused)))
17 {
18 const char *ptr= key;
19 uint32_t value= 0;
20
21 while (key_length--)
22 {
23 uint32_t val= (uint32_t) *ptr++;
24 value += val;
25 value += (value << 10);
26 value ^= (value >> 6);
27 }
28 value += (value << 3);
29 value ^= (value >> 11);
30 value += (value << 15);
31
32 return value;
33 }