-
Notifications
You must be signed in to change notification settings - Fork 1
/
ml1_hash.c
58 lines (55 loc) · 1.77 KB
/
ml1_hash.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdint.h>
#include "lowl.h"
/*
* ML/I Hash.
*
* This is used by both the runtime and the emitter.
*/
/* A little fun in hashing.
* A Pearson hash table that maps the static entries in the ML/I
* hash table in the order defined in the source, from 1 to N. */
static uint8_t t[256] = {
173, 192, 110, 25, 97, 174, 132, 119,
138, 170, 125, 118, 27, 233, 140, 51,
87, 16, 177, 107, 234, 169, 56, 68,
30, 60, 1, 73, 188, 40, 36, 65,
49, 213, 104, 190, 57, 211, 148, 223,
48, 115, 64, 175, 196, 186, 210, 28,
121, 9, 103, 70, 22, 58, 75, 78,
183, 59, 238, 157, 124, 147, 172, 144,
176, 161, 141, 8, 7, 6, 5, 253,
156, 241, 79, 46, 168, 198, 41, 254,
178, 85, 83, 237, 250, 154, 133, 88,
35, 206, 95, 116, 252, 14, 54, 221,
102, 218, 255, 240, 82, 106, 158, 201,
61, 194, 89, 181, 42, 155, 159, 93,
13, 80, 50, 34, 2, 195, 100, 99,
26, 150, 197, 145, 243, 33, 86, 189,
12, 15, 77, 72, 208, 245, 130, 122,
143, 55, 105, 134, 29, 164, 185, 3,
193, 239, 101, 242, 128, 171, 126, 11,
74, 203, 137, 228, 108, 191, 232, 139,
66, 24, 81, 20, 127, 17, 91, 92,
251, 151, 225, 207, 21, 98, 113, 112,
84, 226, 18, 214, 199, 187, 166, 32,
94, 220, 224, 212, 247, 204, 67, 43,
249, 236, 45, 244, 111, 182, 153, 136,
129, 90, 217, 202, 231, 165, 19, 71,
230, 142, 96, 227, 62, 179, 246, 114,
162, 53, 160, 215, 205, 180, 47, 109,
4, 38, 31, 149, 135, 0, 216, 52,
63, 23, 37, 69, 39, 117, 146, 184,
163, 200, 222, 235, 248, 44, 219, 10,
152, 131, 123, 229, 167, 76, 120, 209,
};
uint8_t
ml1_hash(char *s, lowlint_t len)
{
uint8_t hprev, h = 0;
char *e = s + len;
while ( s != e ) {
hprev = h;
h = t[ hprev ^ *s++ ];
}
return h;
}