Expand description
A std::hash::Hasher which is designed to work with already-hashed or hash-like data.
The provided hasher does minimal work under the assumption that the input data is already
suitable for use as a key in a HashSet or HashMap.
As well as the performance benefit, it also causes HashSets or HashMaps to become somewhat
deterministic. Given two equal HashSets or HashMaps containing more than a single element,
iterating them will likely yield the elements in differing orders. By using a
HashedSet or HashedMap, then if the same data is inserted and/or removed in the same
order, iterating the collection will yield a consistent order.
§Examples
Since new() and with_capacity() aren’t available for HashSets or HashMaps using custom
hashers, the available constructors are default(), with_hasher() and
with_capacity_and_hasher().
§Using default()
use hash_hasher::HashedMap;
let mut map = HashedMap::default();
assert!(map.insert(0, "zero").is_none());§Using with_capacity_and_hasher()
use hash_hasher::{HashBuildHasher, HashedSet};
let mut set = HashedSet::with_capacity_and_hasher(100, HashBuildHasher::default());
assert!(set.insert(0));Structs§
- Hash
Hasher - A hasher which does minimal work to create the required
u64output under the assumption that the input is already a hash digest or otherwise already suitable for use as a key in aHashSetorHashMap.
Type Aliases§
- Hash
Build Hasher - Alias for a
BuildHasherDefault<HashHasher>. - Hashed
Map - Alias for a
std::collections::HashMap<K, V, HashBuildHasher>. - Hashed
Set - Alias for a
std::collections::HashSet<K, HashBuildHasher>.