Skip to main content

Module hash

Module hash 

Source
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§

FxBuildHasher
std::hash::BuildHasher for FxHasher, for use as a HashMap’s third type parameter.
FxHashMap
A HashMap keyed with FxHasher.