Annotation of embedaddon/coova-chilli/src/sfhash.c, revision 1.1.1.1
1.1 misho 1: #include "system.h"
2: #undef get16bits
3: #if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \
4: || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__)
5: #define get16bits(d) (*((const uint16_t *) (d)))
6: #endif
7:
8: #if !defined (get16bits)
9: #define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8)\
10: +(uint32_t)(((const uint8_t *)(d))[0]) )
11: #endif
12:
13: uint32_t SuperFastHash (const char * data, int len, uint32_t hash) {
14: uint32_t tmp;
15: int rem;
16:
17: if (len <= 0 || data == NULL) return 0;
18:
19: rem = len & 3;
20: len >>= 2;
21:
22: /* Main loop */
23: for (;len > 0; len--) {
24: hash += get16bits (data);
25: tmp = (get16bits (data+2) << 11) ^ hash;
26: hash = (hash << 16) ^ tmp;
27: data += 2*sizeof (uint16_t);
28: hash += hash >> 11;
29: }
30:
31: /* Handle end cases */
32: switch (rem) {
33: case 3: hash += get16bits (data);
34: hash ^= hash << 16;
35: hash ^= data[sizeof (uint16_t)] << 18;
36: hash += hash >> 11;
37: break;
38: case 2: hash += get16bits (data);
39: hash ^= hash << 11;
40: hash += hash >> 17;
41: break;
42: case 1: hash += *data;
43: hash ^= hash << 10;
44: hash += hash >> 1;
45: }
46:
47: /* Force "avalanching" of final 127 bits */
48: hash ^= hash << 3;
49: hash += hash >> 5;
50: hash ^= hash << 4;
51: hash += hash >> 17;
52: hash ^= hash << 25;
53: hash += hash >> 6;
54:
55: return hash;
56: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>