This patch creates a couple of tests around how autoeject works.
[m6w6/libmemcached] / libhashkit / one_at_a_time.cc
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 <libhashkit/common.h>
15
16 uint32_t hashkit_one_at_a_time(const char *key, size_t key_length, void *context)
17 {
18 const char *ptr= key;
19 uint32_t value= 0;
20 (void)context;
21
22 while (key_length--)
23 {
24 uint32_t val= (uint32_t) *ptr++;
25 value += val;
26 value += (value << 10);
27 value ^= (value >> 6);
28 }
29 value += (value << 3);
30 value ^= (value >> 11);
31 value += (value << 15);
32
33 return value;
34 }