2 #include <linux/ceph/types.h>
3 #include <linux/module.h>
6 * Robert Jenkin's hash function.
7 * http://burtleburtle.net/bob/hash/evahash.html
8 * This is in the public domain.
10 #define mix(a, b, c) \
12 a = a - b; a = a - c; a = a ^ (c >> 13); \
13 b = b - c; b = b - a; b = b ^ (a << 8); \
14 c = c - a; c = c - b; c = c ^ (b >> 13); \
15 a = a - b; a = a - c; a = a ^ (c >> 12); \
16 b = b - c; b = b - a; b = b ^ (a << 16); \
17 c = c - a; c = c - b; c = c ^ (b >> 5); \
18 a = a - b; a = a - c; a = a ^ (c >> 3); \
19 b = b - c; b = b - a; b = b ^ (a << 10); \
20 c = c - a; c = c - b; c = c ^ (b >> 15); \
23 unsigned ceph_str_hash_rjenkins(const char *str
, unsigned length
)
25 const unsigned char *k
= (const unsigned char *)str
;
26 __u32 a
, b
, c
; /* the internal state */
27 __u32 len
; /* how many key bytes still need mixing */
29 /* Set up the internal state */
31 a
= 0x9e3779b9; /* the golden ratio; an arbitrary value */
33 c
= 0; /* variable initialization of internal state */
35 /* handle most of the key */
37 a
= a
+ (k
[0] + ((__u32
)k
[1] << 8) + ((__u32
)k
[2] << 16) +
39 b
= b
+ (k
[4] + ((__u32
)k
[5] << 8) + ((__u32
)k
[6] << 16) +
41 c
= c
+ (k
[8] + ((__u32
)k
[9] << 8) + ((__u32
)k
[10] << 16) +
42 ((__u32
)k
[11] << 24));
48 /* handle the last 11 bytes */
50 switch (len
) { /* all the case statements fall through */
52 c
= c
+ ((__u32
)k
[10] << 24);
54 c
= c
+ ((__u32
)k
[9] << 16);
56 c
= c
+ ((__u32
)k
[8] << 8);
57 /* the first byte of c is reserved for the length */
59 b
= b
+ ((__u32
)k
[7] << 24);
61 b
= b
+ ((__u32
)k
[6] << 16);
63 b
= b
+ ((__u32
)k
[5] << 8);
67 a
= a
+ ((__u32
)k
[3] << 24);
69 a
= a
+ ((__u32
)k
[2] << 16);
71 a
= a
+ ((__u32
)k
[1] << 8);
74 /* case 0: nothing left to add */
84 unsigned ceph_str_hash_linux(const char *str
, unsigned length
)
86 unsigned long hash
= 0;
91 hash
= (hash
+ (c
<< 4) + (c
>> 4)) * 11;
97 unsigned ceph_str_hash(int type
, const char *s
, unsigned len
)
100 case CEPH_STR_HASH_LINUX
:
101 return ceph_str_hash_linux(s
, len
);
102 case CEPH_STR_HASH_RJENKINS
:
103 return ceph_str_hash_rjenkins(s
, len
);
108 EXPORT_SYMBOL(ceph_str_hash
);
110 const char *ceph_str_hash_name(int type
)
113 case CEPH_STR_HASH_LINUX
:
115 case CEPH_STR_HASH_RJENKINS
:
121 EXPORT_SYMBOL(ceph_str_hash_name
);