1 #ifndef KCOMPAT_JHASH_H
2 #define KCOMPAT_JHASH_H
4 /* jhash.h: Jenkins hash support.
6 * Copyright (C) 1996 Bob Jenkins (bob_jenkins@burtleburtle.net)
8 * http://burtleburtle.net/bob/hash/
10 * These are the credits from Bob's sources:
12 * lookup2.c, by Bob Jenkins, December 1996, Public Domain.
13 * hash(), hash2(), hash3, and mix() are externally useful functions.
14 * Routines to test the hash are included if SELF_TEST is defined.
15 * You can use this free for any purpose. It has no warranty.
17 * Copyright (C) 2003 David S. Miller (davem@redhat.com)
19 * I've modified Bob's hash to be useful in the Linux kernel, and
20 * any bugs present are surely my fault. -DaveM
23 /* NOTE: Arguments are modified. */
24 #define __jhash_mix(a, b, c) \
26 a -= b; a -= c; a ^= (c>>13); \
27 b -= c; b -= a; b ^= (a<<8); \
28 c -= a; c -= b; c ^= (b>>13); \
29 a -= b; a -= c; a ^= (c>>12); \
30 b -= c; b -= a; b ^= (a<<16); \
31 c -= a; c -= b; c ^= (b>>5); \
32 a -= b; a -= c; a ^= (c>>3); \
33 b -= c; b -= a; b ^= (a<<10); \
34 c -= a; c -= b; c ^= (b>>15); \
37 /* The golden ration: an arbitrary value */
38 #define JHASH_GOLDEN_RATIO 0x9e3779b9
40 /* The most generic version, hashes an arbitrary sequence
41 * of bytes. No alignment or length assumptions are made about
44 static inline u32
jhash(const void *key
, u32 length
, u32 initval
)
47 const u8
*k
= (const u8
*) key
;
50 a
= b
= JHASH_GOLDEN_RATIO
;
54 a
+= (k
[0] +((u32
)k
[1]<<8) +((u32
)k
[2]<<16) +((u32
)k
[3]<<24));
55 b
+= (k
[4] +((u32
)k
[5]<<8) +((u32
)k
[6]<<16) +((u32
)k
[7]<<24));
56 c
+= (k
[8] +((u32
)k
[9]<<8) +((u32
)k
[10]<<16)+((u32
)k
[11]<<24));
66 case 11: c
+= ((u32
)k
[10]<<24);
67 case 10: c
+= ((u32
)k
[9]<<16);
68 case 9 : c
+= ((u32
)k
[8]<<8);
69 case 8 : b
+= ((u32
)k
[7]<<24);
70 case 7 : b
+= ((u32
)k
[6]<<16);
71 case 6 : b
+= ((u32
)k
[5]<<8);
73 case 4 : a
+= ((u32
)k
[3]<<24);
74 case 3 : a
+= ((u32
)k
[2]<<16);
75 case 2 : a
+= ((u32
)k
[1]<<8);
84 #endif /* KCOMPAT_JHASH_H */
This page took 0.032341 seconds and 5 git commands to generate.