1 /* By Paul Hsieh (C) 2004, 2005. Covered under the Paul Hsieh
3 * See: http://www.azillionmonkeys.com/qed/weblicense.html for license
5 * http://www.azillionmonkeys.com/qed/hash.html
11 #if (defined(__GNUC__) && defined(__i386__))
12 #define get16bits(d) (*((const uint16_t *) (d)))
15 #if !defined (get16bits)
16 #define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8)\
17 +(uint32_t)(((const uint8_t *)(d))[0]) )
20 uint32_t hashkit_hsieh(const char *key
, size_t key_length
, void *context
__attribute__((unused
)))
22 uint32_t hash
= 0, tmp
;
25 if (key_length
<= 0 || key
== NULL
)
32 for (;key_length
> 0; key_length
--)
34 hash
+= get16bits (key
);
35 tmp
= (get16bits (key
+2) << 11) ^ hash
;
36 hash
= (hash
<< 16) ^ tmp
;
37 key
+= 2*sizeof (uint16_t);
41 /* Handle end cases */
44 case 3: hash
+= get16bits (key
);
46 hash
^= (uint32_t)key
[sizeof (uint16_t)] << 18;
49 case 2: hash
+= get16bits (key
);
53 case 1: hash
+= (unsigned char)(*key
);
60 /* Force "avalanching" of final 127 bits */