Index: Source/wtf/HashTable.cpp |
diff --git a/Source/wtf/HashTable.cpp b/Source/wtf/HashTable.cpp |
index 518a4c8c24ae5cda1fb0c6769ef604bf193dd7c1..5bcc370a51ecbeca6a708b5a61a8fa45b147522c 100644 |
--- a/Source/wtf/HashTable.cpp |
+++ b/Source/wtf/HashTable.cpp |
@@ -65,4 +65,81 @@ void HashTableStats::dumpStats() |
#endif |
+// integer hash function |
+ |
+// Thomas Wang's 32 Bit Mix Function: http://www.cris.com/~Ttwang/tech/inthash.htm |
+unsigned intHash(uint8_t key8) |
+{ |
+ unsigned key = key8; |
+ key += ~(key << 15); |
+ key ^= (key >> 10); |
+ key += (key << 3); |
+ key ^= (key >> 6); |
+ key += ~(key << 11); |
+ key ^= (key >> 16); |
+ return key; |
+} |
+ |
+// Thomas Wang's 32 Bit Mix Function: http://www.cris.com/~Ttwang/tech/inthash.htm |
+unsigned intHash(uint16_t key16) |
+{ |
+ unsigned key = key16; |
+ key += ~(key << 15); |
+ key ^= (key >> 10); |
+ key += (key << 3); |
+ key ^= (key >> 6); |
+ key += ~(key << 11); |
+ key ^= (key >> 16); |
+ return key; |
+} |
+ |
+// Thomas Wang's 32 Bit Mix Function: http://www.cris.com/~Ttwang/tech/inthash.htm |
+unsigned intHash(uint32_t key) |
+{ |
+ key += ~(key << 15); |
+ key ^= (key >> 10); |
+ key += (key << 3); |
+ key ^= (key >> 6); |
+ key += ~(key << 11); |
+ key ^= (key >> 16); |
+ return key; |
+} |
+ |
+// Thomas Wang's 64 bit Mix Function: http://www.cris.com/~Ttwang/tech/inthash.htm |
+unsigned intHash(uint64_t key) |
+{ |
+ key += ~(key << 32); |
+ key ^= (key >> 22); |
+ key += ~(key << 13); |
+ key ^= (key >> 8); |
+ key += (key << 3); |
+ key ^= (key >> 15); |
+ key += ~(key << 27); |
+ key ^= (key >> 31); |
+ return static_cast<unsigned>(key); |
+} |
+ |
+// Compound integer hash method: http://opendatastructures.org/versions/edition-0.1d/ods-java/node33.html#SECTION00832000000000000000 |
+unsigned pairIntHash(unsigned key1, unsigned key2) |
+{ |
+ unsigned shortRandom1 = 277951225; // A random 32-bit value. |
+ unsigned shortRandom2 = 95187966; // A random 32-bit value. |
+ uint64_t longRandom = 19248658165952622LL; // A random 64-bit value. |
+ |
+ uint64_t product = longRandom * (shortRandom1 * key1 + shortRandom2 * key2); |
+ unsigned highBits = static_cast<unsigned>(product >> (sizeof(uint64_t) - sizeof(unsigned))); |
+ return highBits; |
+} |
+ |
+// Custom secondary hash function. |
+unsigned doubleHash(unsigned key) |
+{ |
+ key = ~key + (key >> 23); |
+ key ^= (key << 12); |
+ key ^= (key >> 7); |
+ key ^= (key << 2); |
+ key ^= (key >> 20); |
+ return key; |
+} |
+ |
} // namespace WTF |