MCPcopy Create free account
hub / github.com/IoLanguage/io / SuperFastHash

Function SuperFastHash

libs/basekit/source/Hash_superfast.c:16–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14#endif
15
16uint32_t SuperFastHash(const char *data, int len) {
17 uint32_t hash = len, tmp;
18 int rem;
19
20 if (len <= 0 || data == NULL)
21 return 0;
22
23 rem = len & 3;
24 len >>= 2;
25
26 /* Main loop */
27 for (; len > 0; len--) {
28 hash += get16bits(data);
29 tmp = (get16bits(data + 2) << 11) ^ hash;
30 hash = (hash << 16) ^ tmp;
31 data += 2 * sizeof(uint16_t);
32 hash += hash >> 11;
33 }
34
35 /* Handle end cases */
36 switch (rem) {
37 case 3:
38 hash += get16bits(data);
39 hash ^= hash << 16;
40 hash ^= data[sizeof(uint16_t)] << 18;
41 hash += hash >> 11;
42 break;
43 case 2:
44 hash += get16bits(data);
45 hash ^= hash << 11;
46 hash += hash >> 17;
47 break;
48 case 1:
49 hash += *data;
50 hash ^= hash << 10;
51 hash += hash >> 1;
52 }
53
54 /* Force "avalanching" of final 127 bits */
55 hash ^= hash << 3;
56 hash += hash >> 5;
57 hash ^= hash << 4;
58 hash += hash >> 17;
59 hash ^= hash << 25;
60 hash += hash >> 6;
61
62 return hash;
63}

Callers 1

UArray_superfastHashFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected