1 // From http://www.azillionmonkeys.com/qed/hash.html
5 typedef uint32
uint32_t;
6 typedef uint16
uint16_t;
11 #if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \
12 || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__)
13 #define get16bits(d) (*((const uint16_t *) (d)))
16 #if !defined (get16bits)
17 #define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8)\
18 +(uint32_t)(((const uint8_t *)(d))[0]) )
21 uint32
SuperFastHash(const char * data
, int len
) {
22 uint32_t hash
= len
, tmp
;
25 if (len
<= 0 || data
== NULL
)
32 for (; len
> 0; len
--) {
33 hash
+= get16bits(data
);
34 tmp
= (get16bits(data
+ 2) << 11) ^ hash
;
35 hash
= (hash
<< 16) ^ tmp
;
36 data
+= 2 * sizeof(uint16_t);
40 /* Handle end cases */
43 hash
+= get16bits(data
);
46 // Treat the final character as signed. This ensures all platforms behave
47 // consistently with the original x86 code.
48 hash
^= static_cast<signed char>(data
[sizeof(uint16_t)]) << 18;
52 hash
+= get16bits(data
);
57 hash
+= static_cast<signed char>(*data
);
62 /* Force "avalanching" of final 127 bits */