2 #include <linux/types.h>
6 * Robert Jenkins' function for mixing 32-bit values
7 * http://burtleburtle.net/bob/hash/evahash.html
8 * a, b = random bits, c = input and output
10 #define crush_hashmix(a, b, c) do { \
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 #define crush_hash_seed 1315423911
24 static __u32
crush_hash32_rjenkins1(__u32 a
)
26 __u32 hash
= crush_hash_seed
^ a
;
30 crush_hashmix(b
, x
, hash
);
31 crush_hashmix(y
, a
, hash
);
35 static __u32
crush_hash32_rjenkins1_2(__u32 a
, __u32 b
)
37 __u32 hash
= crush_hash_seed
^ a
^ b
;
40 crush_hashmix(a
, b
, hash
);
41 crush_hashmix(x
, a
, hash
);
42 crush_hashmix(b
, y
, hash
);
46 static __u32
crush_hash32_rjenkins1_3(__u32 a
, __u32 b
, __u32 c
)
48 __u32 hash
= crush_hash_seed
^ a
^ b
^ c
;
51 crush_hashmix(a
, b
, hash
);
52 crush_hashmix(c
, x
, hash
);
53 crush_hashmix(y
, a
, hash
);
54 crush_hashmix(b
, x
, hash
);
55 crush_hashmix(y
, c
, hash
);
59 static __u32
crush_hash32_rjenkins1_4(__u32 a
, __u32 b
, __u32 c
, __u32 d
)
61 __u32 hash
= crush_hash_seed
^ a
^ b
^ c
^ d
;
64 crush_hashmix(a
, b
, hash
);
65 crush_hashmix(c
, d
, hash
);
66 crush_hashmix(a
, x
, hash
);
67 crush_hashmix(y
, b
, hash
);
68 crush_hashmix(c
, x
, hash
);
69 crush_hashmix(y
, d
, hash
);
73 static __u32
crush_hash32_rjenkins1_5(__u32 a
, __u32 b
, __u32 c
, __u32 d
,
76 __u32 hash
= crush_hash_seed
^ a
^ b
^ c
^ d
^ e
;
79 crush_hashmix(a
, b
, hash
);
80 crush_hashmix(c
, d
, hash
);
81 crush_hashmix(e
, x
, hash
);
82 crush_hashmix(y
, a
, hash
);
83 crush_hashmix(b
, x
, hash
);
84 crush_hashmix(y
, c
, hash
);
85 crush_hashmix(d
, x
, hash
);
86 crush_hashmix(y
, e
, hash
);
91 __u32
crush_hash32(int type
, __u32 a
)
94 case CRUSH_HASH_RJENKINS1
:
95 return crush_hash32_rjenkins1(a
);
101 __u32
crush_hash32_2(int type
, __u32 a
, __u32 b
)
104 case CRUSH_HASH_RJENKINS1
:
105 return crush_hash32_rjenkins1_2(a
, b
);
111 __u32
crush_hash32_3(int type
, __u32 a
, __u32 b
, __u32 c
)
114 case CRUSH_HASH_RJENKINS1
:
115 return crush_hash32_rjenkins1_3(a
, b
, c
);
121 __u32
crush_hash32_4(int type
, __u32 a
, __u32 b
, __u32 c
, __u32 d
)
124 case CRUSH_HASH_RJENKINS1
:
125 return crush_hash32_rjenkins1_4(a
, b
, c
, d
);
131 __u32
crush_hash32_5(int type
, __u32 a
, __u32 b
, __u32 c
, __u32 d
, __u32 e
)
134 case CRUSH_HASH_RJENKINS1
:
135 return crush_hash32_rjenkins1_5(a
, b
, c
, d
, e
);
141 const char *crush_hash_name(int type
)
144 case CRUSH_HASH_RJENKINS1
: