The fast, non-cryptographic FxHasher that rustc uses, with FxHashMap and FxHashSet
open sourceApache-2.0 OR MITfree
rustc-hash is the Rust project's crate for the fast, non-cryptographic hash the compiler uses. It gives FxHashMap and FxHashSet, type aliases for the standard library's collections with the Fx hasher in place of SipHash, which the standard HashMap uses by default for resistance to denial-of-service attacks. The hasher kept its FxHasher name from the Firefox algorithm it started with, but is now a polynomial hash with a wyhash-inspired compression function for strings and slices. It works without std.
Problems it solves
- HashMap lookups in my Rust code are slow because of the default SipHash
- a faster hasher for integer keys where denial-of-service resistance doesn't matter
- fast hash maps in a no_std Rust crate
Features
- FxHashMap and FxHashSet type aliases
- fast non-cryptographic hasher
- no_std support with the std feature off
Limitations
- Not resistant to hash-flooding denial-of-service attacks, unlike the standard library's SipHash default1
Alternatives
The same job
These do what rustc-hash does.
- hashbrown SwissTable-based HashMap and HashSet for Rust, the implementation behind the standard library's
- RustCrypto Hashes Collection of cryptographic hash functions written in pure Rust
