Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2768)

Unified Diff: Source/wtf/HashTable.cpp

Issue 373423003: Save 100-300 KB footprint by not force inlining HashTable functions Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Non-inlined HashTable: Rebased to newer origin/master Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/wtf/HashTable.h ('k') | Source/wtf/ListHashSet.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « Source/wtf/HashTable.h ('k') | Source/wtf/ListHashSet.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698