Skip to content

Commit 944120b

Browse files
committed
Hash bits finisher for power-of-2 masking hash reducer
1 parent 0269d7f commit 944120b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/Common/DataStructures/SizePolicy.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ struct PowerOf2Policy
3232
inline static hash_t GetBucket(hash_t hashCode, uint size, int modFunctionIndex)
3333
{
3434
AssertMsg(Math::IsPow2(size) && size > 1, "Size is not a power of 2.");
35+
36+
// we often deal with keys that differ in higher bits only, so smudge the entropy down a little
37+
// we do not need a perfect avalanche here, since this is for a hashtable lookup
38+
// the following is sufficient and reasonably cheap
39+
hashCode ^= (uint)hashCode >> 15;
40+
hashCode ^= (uint)hashCode >> 7;
41+
3542
hash_t targetBucket = hashCode & (size-1);
3643
return targetBucket;
3744
}

0 commit comments

Comments
 (0)