mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:24:57 +00:00
AK: Redesign HashTable to use closed hashing
Instead of each hash bucket being a SinglyLinkedList, switch to using closed hashing (open addressing). Buckets are chained together via double hashing (hashing the hash until we find an unused bucket.) This greatly reduces malloc traffic, since each added element no longer allocates a new linked list node. Appears performance neutral on test-js. Can definitely be tuned and could use proper management of load factor, etc.
This commit is contained in:
parent
4387590e65
commit
4e50079f36
2 changed files with 248 additions and 267 deletions
|
@ -39,6 +39,16 @@ inline unsigned int_hash(u32 key)
|
|||
return key;
|
||||
}
|
||||
|
||||
inline unsigned double_hash(u32 key)
|
||||
{
|
||||
key = ~key + (key >> 23);
|
||||
key ^= (key << 12);
|
||||
key ^= (key >> 7);
|
||||
key ^= (key << 2);
|
||||
key ^= (key >> 20);
|
||||
return key;
|
||||
}
|
||||
|
||||
inline unsigned pair_int_hash(u32 key1, u32 key2)
|
||||
{
|
||||
return int_hash((int_hash(key1) * 209) ^ (int_hash(key2 * 413)));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue