core::hash
On this page
what a Hash impl writes to:
Hasher, BuildHasher, the process-keyed RandomState that Dict
and Set default to with its SipHash-1-3 DefaultHasher, and the
caller-keyed SipHasher13 / SipHasher24, whose output is stable.
Structs
RandomStateSource
pub struct RandomStateThe process's hash key, what Dict and Set use by default: drawn
at random once per process, so where a key lands changes between
runs (but not what a dict prints: that follows insertion order).
Every RandomState::new() in a process holds the same key.
The process's keys: every
RandomStateof the process hashes alike.
DefaultHasherSource
pub struct DefaultHasherRandomState's hasher. The algorithm (SipHash-1-3 today) and so its
output are unspecified and may change in any release: never persist
it. SipHasher13 is the stable form.
SipHasher13Source
pub struct SipHasher13SipHash-1-3 under a caller's key. Its output for the bytes written
is the reference SipHash and stable across releases; write_<int>
writes the integer's little-endian bytes (write_usize 8). The
writes a Hash impl makes are not stable, so a persisted hash feeds
bytes and integers directly, never x.hash(ref h).
A hasher under the 128-bit key
k0,k1.
SipHasher24Source
pub struct SipHasher24SipHash-2-4 under a caller's key: as SipHasher13, with the
original paper's rounds.
A hasher under the 128-bit key
k0,k1.
BuildHasherDefaultSource
pub struct BuildHasherDefault<H>Builds H::default(): for a Dict / Set with a fixed hasher of
the caller's (Dict<K, V, BuildHasherDefault<MyHasher>>). Use one
only when keys cannot come from an attacker.
The builder; it holds nothing.
Traits
HasherSource
pub trait HasherA running hash: Hash impls feed it bytes and integers, finish
reads the result. Equal values must make the same sequence of
writes; a variable-length run of values starts with
write_length_prefix, so that ("ab", "c") and ("a", "bc") differ.
Raw bytes; adds no length or terminator.
The hash of everything written so far; the state is not reset.
xas one byte.xas 2 little-endian bytes.xas 4 little-endian bytes.xas 8 little-endian bytes.8 bytes on every target, so a hash does not depend on the width.
xaswrite_u8of its bits.xaswrite_u16of its bits.xaswrite_u32of its bits.xaswrite_u64of its bits.xaswrite_u64of its bits, on every target.Before a variable-length run of
Hashvalues (a list's items).A whole
str, prefix-free on its own: never precede it withwrite_length_prefix.
BuildHasherSource
pub trait BuildHasherMakes the Hashers of a Dict / Set: every one it builds hashes
equal values alike.
The hasher it builds.
A new hasher; every one starts from the same state.