pub type Map<K, V> = HashMap<K, V>;Expand description
The default owned HashMap type generated map<K, V> fields use.
On std builds this resolves to std::collections::HashMap<K, V, foldhash::fast::RandomState>; on no_std builds it is
hashbrown::HashMap<K, V> (which defaults to the same foldhash hasher).
This alias is the recommended way to name a generated map field’s type in
downstream code, so that the concrete hasher and container stay an
implementation detail.
Re-exported at the crate root as buffa::Map, alongside MapStorage:
use buffa::Map;.
§Construction
Use Map::default to construct an empty map. The inherent
HashMap::new() and HashMap::with_capacity() are only defined for the
std default hasher, so they are unavailable on Map under std (and would
be non-portable across the std/no_std boundary). For literals, use
[(k, v), ..].into_iter().collect() rather than Map::from([...]) —
From<[_; N]> is likewise hasher-pinned in std. To preallocate, use
std::collections::HashMap::with_capacity_and_hasher(n, Default::default()).
§Hasher and HashDoS
foldhash::fast is per-instance seeded — each Map::default() derives a
fresh seed from the stack pointer mixed with a thread-local counter,
layered on a process-wide seed derived from ASLR addresses and process
start time. That nondeterminism means a single static collision set will
not transfer across processes, but the seed is not drawn from a
CSPRNG (unlike std::hash::RandomState, which seeds SipHash from
getrandom), and foldhash::fast does not advertise HashDoS resistance.
Treat this default as not hardened against adversarial hash flooding.
This is the same trade-off Google’s protobuf-v4/upb makes (Wyhash).
Consumers decoding map fields with attacker-controlled keys who need a
hardened bound should select MapRepr::BTreeMap (no hashing, O(log n)
worst case) or supply a SipHash-backed map via MapRepr::Custom. The
MapStorage impl is generic over the hasher, so
std::collections::HashMap<K, V, std::hash::RandomState> works without a
newtype — only a foreign container type (e.g. IndexMap) needs one.
Aliased Type§
pub struct Map<K, V> { /* private fields */ }