root / lab4 / .minix-src / include / minix / hash.h @ 14
History | View | Annotate | Download (1.1 KB)
1 | 13 | up20180614 | |
---|---|---|---|
2 | #ifndef _MINIX_HASH_H
|
||
3 | #define _MINIX_HASH_H 1 |
||
4 | |||
5 | #include <stdint.h> |
||
6 | |||
7 | /* This code is taken from:
|
||
8 | * lookup3.c, by Bob Jenkins, May 2006, Public Domain.
|
||
9 | * (macro names modified)
|
||
10 | */
|
||
11 | |||
12 | #define hash_rot(x,k) (((x)<<(k)) | ((x)>>(32-(k)))) |
||
13 | |||
14 | #define hash_mix(a,b,c) \
|
||
15 | { \ |
||
16 | a -= c; a ^= hash_rot(c, 4); c += b; \
|
||
17 | b -= a; b ^= hash_rot(a, 6); a += c; \
|
||
18 | c -= b; c ^= hash_rot(b, 8); b += a; \
|
||
19 | a -= c; a ^= hash_rot(c,16); c += b; \
|
||
20 | b -= a; b ^= hash_rot(a,19); a += c; \
|
||
21 | c -= b; c ^= hash_rot(b, 4); b += a; \
|
||
22 | } |
||
23 | |||
24 | #define hash_final(a,b,c) \
|
||
25 | { \ |
||
26 | c ^= b; c -= hash_rot(b,14); \
|
||
27 | a ^= c; a -= hash_rot(c,11); \
|
||
28 | b ^= a; b -= hash_rot(a,25); \
|
||
29 | c ^= b; c -= hash_rot(b,16); \
|
||
30 | a ^= c; a -= hash_rot(c,4); \
|
||
31 | b ^= a; b -= hash_rot(a,14); \
|
||
32 | c ^= b; c -= hash_rot(b,24); \
|
||
33 | } |
||
34 | |||
35 | #define hash_i_64(a, u, v) { \
|
||
36 | u32_t i1 = (a), i2 = ex64lo(u), i3 = ex64hi(u); \ |
||
37 | hash_mix(i1, i2, i3); \ |
||
38 | hash_final(i1, i2, i3); \ |
||
39 | (v) = i3; \ |
||
40 | } |
||
41 | |||
42 | #define hash_32(n, v) { \
|
||
43 | u32_t i1 = 0xa5a5a5a5, i2 = 0x12345678, i3 = n; \ |
||
44 | hash_mix(i1, i2, i3); \ |
||
45 | hash_final(i1, i2, i3); \ |
||
46 | (v) = i3; \ |
||
47 | } |
||
48 | |||
49 | #endif |