Created a bigger buffer for write/read.
[m6w6/libmemcached] / lib / memcached_hash.c
1 #include "common.h"
2
3 /* Prototypes */
4 static unsigned int internal_generate_hash(char *key, size_t key_length);
5
6 unsigned int memcached_generate_hash(memcached_st *ptr, char *key, size_t key_length)
7 {
8 unsigned int hash;
9
10 if (ptr->flags & MEM_USE_MD5)
11 {
12 unsigned char results[16];
13
14 md5_signature((unsigned char*)key, (unsigned int)key_length, results);
15
16 hash= (unsigned int)(( results[3] << 24 )
17 | ( results[2] << 16 )
18 | ( results[1] << 8 )
19 | results[0] );
20 }
21 else
22 hash= internal_generate_hash(key, key_length);
23
24 if (ptr->flags & MEM_USE_KETAMA)
25 assert(0);
26 else
27 return hash % ptr->number_of_hosts;
28 }
29
30 static unsigned int internal_generate_hash(char *key, size_t key_length)
31 {
32 char *ptr= key;
33 unsigned int value= 0;
34
35 while (--key_length)
36 {
37 value += *ptr++;
38 value += (value << 10);
39 value ^= (value >> 6);
40 }
41 value += (value << 3);
42 value ^= (value >> 11);
43 value += (value << 15);
44
45 return value == 0 ? 1 : value;
46 }