4 ms·
The key effect of Robin Hood hashing is just that it gives you confidence and/or hubris to push a table to 90% capacity, which greatly exacerbates the problem.
by Animats 10y ago
The key effect of Robin Hood hashing is just that it gives you confidence and/or hubris to push a table to 90% capacity, which greatly exacerbates the problem.
If you push a hash table which handles collisions by linear probing that hard, and any non-randomness appears, you can get long runs and are in trouble. I knew about Robin Hood hashing, but didn't know it was being used to justify 90% table density. Usually, above 50% full and it's time to double the size of the table.
What does the Rust implementation do for deletions? The classic solution is to mark the deleted cell as available for reuse, but non-empty for the linear part of the search during lookup. If you do that, at some point you have to compact the table or recopy it or something. This is an argument for a hash table with linear lists for each hash slot. More memory allocations and cache misses, but better behavior as the table fills up.
(Remember the YC discussion in which some job interview question insisted that hash tables operated in constant (O(1)) time? Not quite. There's collision overhead and growth overhead.)
- doomrobo 10y agoFrom the docs page [0] for std::collections::HashMap, Rust uses backwards shift deletion [1] instead of the tombstone method. [0] https://doc.rust-lang.org/std/collections/struct.HashMap.html https://doc.rust-lang.org/std/collections/struct.HashMap.htm... [1] http://codecapsule.com/2013/11/17/robin-hood-hashing-backward-shift-deletion/ http://codecapsule.com/2013/11/17/robin-hood-hashing-backwar...
- Animats 10y agoThat makes sense. With the tombstone method, hashmaps get worse with age.
- bakhy 10y ago> If you push a hash table which handles collisions by linear probing that hard, and any non-randomness appears, you can get long runs and are in trouble. I knew about Robin Hood hashing, but didn't know it was being used to justify 90% table density. Usually, above 50% full and it's time to double the size of the table. wouldn't non-randomness be an issue for any hash table, regardless of how full it is? doubling it will not make the input more random, theoretically we could have the same slowness whether it's a smaller 90% full table, or a bigger one "just" 45% full - if N things hash to the same loc, we'll have to dig through O(N) spots till we find what we need. i wrote a small hash set for my side project (https://github.com/jbakic/Shielded/blob/master/Shielded/SimpleHashSet.cs https://github.com/jbakic/Shielded/blob/master/Shielded/Simp..., does not need to support removal so it's the dumbest linear probing hash table one could probably imagine), and there i set the limit at 75%, even though i don't use Robin Hood (perhaps i should?), because the lib has to iterate through the whole set at the end of a transaction, at least twice. i know this is not very relevant, a very special use case, but i'm giving it as an example of how a bigger load factor can actually be advantageous. the Shielded lib is overall slower if the load factor limit is set lower. i hope someone more versed in the theory behind all this can add something to this, i'm curious if my thinking really makes sense...