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 hsieh_hash(char *key
, size_t key_length
)
22 uint32_t hash
= 0, tmp
;
25 if (key_length
<= 0 || key
== NULL
) return 0;
31 for (;key_length
> 0; key_length
--) {
32 hash
+= get16bits (key
);
33 tmp
= (get16bits (key
+2) << 11) ^ hash
;
34 hash
= (hash
<< 16) ^ tmp
;
35 key
+= 2*sizeof (uint16_t);
39 /* Handle end cases */
41 case 3: hash
+= get16bits (key
);
43 hash
^= key
[sizeof (uint16_t)] << 18;
46 case 2: hash
+= get16bits (key
);
55 /* Force "avalanching" of final 127 bits */