by the_duke · 5y ago · 0 comments
Here is the relevant explanation from Wikipedia :
> The new key is inserted in one of its two possible locations, "kicking out", that is, displacing, any key that might already reside in this location. This displaced key is then inserted in its alternative location, again kicking out any key that might reside there. The process continues in the same way until an empty position is found, completing the algorithm. However, it is possible for this insertion process to fail, by entering an infinite loop or by finding a very long chain (longer than a preset threshold that is logarithmic in the table size). In this case, the hash table is rebuilt in-place using new hash functions
https://en.wikipedia.org/wiki/Cuckoo_hashing#Operation
Sound like with high occupancy the table would need to be rebuilt constantly.
we must not use the same programs :-(
Not something you can really describe as wildly erratic.
If latency is particularly critical in your application, you could couple the hash table with a small "stash" map and perform a constant maximum number of kicks per insert, and when you reach the limit stick the current straggler in the map to be continued on the next insertion. As long as the constant maximum is well above the average the map will stay empty most of the time.
There is a related e-mail from IdSoft's John Carmack about this at [1] which I found very interesting.
[1] http://number-none.com/blow/blog/programming/2014/09/26/carm...
What matters for realtime operation is that the worst case is bounded and that the bound is acceptable.
> A typical hash function distributes keys randomly across the slots in a hash table, causing some slots to be empty, while others have collisions, which require some form of chaining of items
I.e. each field in the table is a linked list of values that hash to this position, and the new value is inserted in the shortest of the two lists it hashes to.