Module rustc_hash
A fast, non-cryptographic hash function, used by rustc.
- Crate
::rustc_hash. - docs.rs
- crates.io
- GitHub
rustc-hash provides FxHasher,
the hash function the Rust compiler uses for its own hash maps,
and the FxHashMap and FxHashSet aliases for using it
with the standard collections.
FxHasher is faster than the standard HashMap's SipHash,
particularly for small keys like integers and short strings.
It is not resistant to denial-of-service attacks against hash maps,
so it should only hash keys an attacker cannot choose.
Use ahash when keys come from untrusted input.
Unlike ahash, FxHasher is not randomly seeded.
The same keys hash the same way on every run.
That makes iteration order repeatable between runs of a program,
which helps when reproducing bugs,
though programs should not depend on it.
Hashes can still differ between platforms and crate versions.
rustc-hash works in no-std;
there, use FxBuildHasher with hashbrown's maps.
Examples
Using FxHashMap in place of HashMap.
Construct it with default, since new is only defined
for the standard hasher:
use ;
let mut map: = default;
map.insert;
map.insert;
assert_eq!;
let set: = .into_iter.collect;
assert_eq!;
Using FxBuildHasher with a capacity:
use FxBuildHasher;
use HashMap;
let mut map = with_capacity_and_hasher;
map.insert;
assert_eq!;
Structs
-
FxBuildHasher
An implementation of
BuildHasherthat producesFxHashers. - FxHasher A speedy hash algorithm for use within rustc. The hashmap in liballoc by default uses SipHash which isn't quite as speedy as we want. In the compiler we're not really worried about DOS attempts, so we use a fast non-cryptographic hash.
-
FxSeededState
FxSeededStateis an alternative state forHashMaptypes, allowing to useFxHasherwith a set seed.
Type Aliases
- FxHashMap Type alias for a hash map that uses the Fx hashing algorithm.
-
FxHashMapSeed
Type alias for a hashmap using the
fxhash algorithm withFxSeededState. - FxHashSet Type alias for a hash set that uses the Fx hashing algorithm.
-
FxHashSetSeed
Type alias for a hashmap using the
fxhash algorithm withFxSeededState.