4 static unsigned int internal_generate_hash(char *key
, size_t key_length
);
6 unsigned int memcached_generate_hash(memcached_st
*ptr
, char *key
, size_t key_length
)
10 if (ptr
->flags
& MEM_USE_MD5
)
12 unsigned char results
[16];
14 md5_signature((unsigned char*)key
, (unsigned int)key_length
, results
);
16 hash
= (unsigned int)(( results
[3] << 24 )
17 | ( results
[2] << 16 )
22 hash
= internal_generate_hash(key
, key_length
);
24 if (ptr
->flags
& MEM_USE_KETAMA
)
27 return hash
% ptr
->number_of_hosts
;
30 static unsigned int internal_generate_hash(char *key
, size_t key_length
)
33 unsigned int value
= 0;
38 value
+= (value
<< 10);
39 value
^= (value
>> 6);
41 value
+= (value
<< 3);
42 value
^= (value
>> 11);
43 value
+= (value
<< 15);
45 return value
== 0 ? 1 : value
;