Re:Show HN: Whirlwind – Async concurrent hashmap for Rust
by KolmogorovComp on Tuesday November 05, 2024 @03:35PM
(#42054916)
Great crate! Why use a hashmap instead of a Btreemap which is usually advised in rust?
[ Parent
| on HN ]
Re:Show HN: Whirlwind – Async concurrent hashmap for Rust
by willothy on Tuesday November 05, 2024 @03:40PM
(#42054959)
There are a few reasons - For one, I'm not sure BTreeMap is always faster in Rust... it may be sometimes but lookups are still O(log(n)) due to the searching where with a HashMap it's (mostly) O(1). They both have their uses - I usually go for BTreeMap when I explicitly need the collection to be ordered.
A second reason is sharding - sharding based on a hash is quite simple to do, but sharding an ordered collection would be quite difficult since some reads would need to search across multiple shards and thus take multiple locks.
If you mean internally (like for each shard), we're using hashbrown's raw HashTable API because it allows us to manage hashing entirely ourselves, and avoid recomputing the hash when determining the shard and looking up a key within a shard.
Re:Show HN: Whirlwind – Async concurrent hashmap for Rust
by aw1621107 on Tuesday November 05, 2024 @03:39PM
(#42054957)
> Why use a hashmap instead of a Btreemap which is usually advised in rust?
Is this actually the case? I can't say I've seen the same.
Re:Show HN: Whirlwind – Async concurrent hashmap for Rust
by CyberDildonics on Tuesday November 05, 2024 @06:18PM
(#42056052)
Why would you use a b tree if you don't need sorting? It will not only be slower but require a lot more to make lock free (is this hash map lock free?).