Expand description
Fast hashing for n-gram keys A fast hasher for n-gram keys.
Every byte of every sample passes through a hash: once per window to find the n-grams,
and once per window again to featurize against them. The standard library’s
std::hash::DefaultHasher is SipHash, chosen to resist collision attacks on
attacker-supplied keys. N-gram keys are eight bytes of a file being analysed, not map keys
an attacker can pick to degrade a lookup, and SipHash’s setup cost dominates at that size:
measured over 64 MiB of windows it costs 6.2 ns each against 0.3 ns for the hasher here.
This is the rustc-hash (FxHash) algorithm — a rotate, xor and multiply per eight bytes. It is written out rather than pulled in as a dependency because it is twenty lines.
Structs§
- FxHasher
- Fast, non-cryptographic hasher for short byte keys.
Functions§
- hash_
bytes - Hash a byte slice in one call.
Type Aliases§
- FxBuild
Hasher std::hash::BuildHasherforFxHasher, for use as aHashMap’s third type parameter.- FxHash
Map - A
HashMapkeyed withFxHasher.