2 #include <linux/ceph/types.h>
5 * Robert Jenkin's hash function.
6 * http://burtleburtle.net/bob/hash/evahash.html
7 * This is in the public domain.
11 a = a - b; a = a - c; a = a ^ (c >> 13); \
12 b = b - c; b = b - a; b = b ^ (a << 8); \
13 c = c - a; c = c - b; c = c ^ (b >> 13); \
14 a = a - b; a = a - c; a = a ^ (c >> 12); \
15 b = b - c; b = b - a; b = b ^ (a << 16); \
16 c = c - a; c = c - b; c = c ^ (b >> 5); \
17 a = a - b; a = a - c; a = a ^ (c >> 3); \
18 b = b - c; b = b - a; b = b ^ (a << 10); \
19 c = c - a; c = c - b; c = c ^ (b >> 15); \
22 unsigned ceph_str_hash_rjenkins(const char *str, unsigned length)
24 const unsigned char *k = (const unsigned char *)str;
25 __u32 a, b, c; /* the internal state */
26 __u32 len; /* how many key bytes still need mixing */
28 /* Set up the internal state */
30 a = 0x9e3779b9; /* the golden ratio; an arbitrary value */
32 c = 0; /* variable initialization of internal state */
34 /* handle most of the key */
36 a = a + (k[0] + ((__u32)k[1] << 8) + ((__u32)k[2] << 16) +
38 b = b + (k[4] + ((__u32)k[5] << 8) + ((__u32)k[6] << 16) +
40 c = c + (k[8] + ((__u32)k[9] << 8) + ((__u32)k[10] << 16) +
41 ((__u32)k[11] << 24));
47 /* handle the last 11 bytes */
49 switch (len) { /* all the case statements fall through */
51 c = c + ((__u32)k[10] << 24);
53 c = c + ((__u32)k[9] << 16);
55 c = c + ((__u32)k[8] << 8);
56 /* the first byte of c is reserved for the length */
58 b = b + ((__u32)k[7] << 24);
60 b = b + ((__u32)k[6] << 16);
62 b = b + ((__u32)k[5] << 8);
66 a = a + ((__u32)k[3] << 24);
68 a = a + ((__u32)k[2] << 16);
70 a = a + ((__u32)k[1] << 8);
73 /* case 0: nothing left to add */
83 unsigned ceph_str_hash_linux(const char *str, unsigned length)
85 unsigned long hash = 0;
90 hash = (hash + (c << 4) + (c >> 4)) * 11;
96 unsigned ceph_str_hash(int type, const char *s, unsigned len)
99 case CEPH_STR_HASH_LINUX:
100 return ceph_str_hash_linux(s, len);
101 case CEPH_STR_HASH_RJENKINS:
102 return ceph_str_hash_rjenkins(s, len);
108 const char *ceph_str_hash_name(int type)
111 case CEPH_STR_HASH_LINUX:
113 case CEPH_STR_HASH_RJENKINS: