jonhoo / flurry

A port of Java's ConcurrentHashMap to Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow use of pre-hashed keys

conradludgate opened this issue · comments

As an optimisation, I want to be able to memoize a key-hash. My current solution is double-hashing with the first hash being key -> u64, then the second hash using a no-op hasher from u64 -> u64. However, this requires storing the hash twice in the hashmap.

I'm ok with such methods being unsafe if necessary, but the hashbrown equivalents are completely safe https://docs.rs/hashbrown/latest/hashbrown/hash_map/struct.RawEntryBuilder.html#method.from_key_hashed_nocheck

Ah, so, they're safe only because hash <> key mismatches result only in correctness errors, not memory safety errors. I'm not sure whether the same would be true for the concurrent structure in flurry. I think we could probably expose a similar API though! PRs welcome :)