Skip to main content

Module hash

Module hash 

Source
Expand description

Hashing infrastructure shared by every structure.

Probabilistic data structures live and die by the quality of their hash function: poor mixing inflates the false-positive rate and skews cardinality estimates. This module supplies a fast, high-quality, deterministic default hasher and the machinery to derive the multiple index hashes each structure needs from a single pass over the input.

§Choosing a hasher

Every structure is generic over core::hash::BuildHasher and defaults to DefaultHashBuilder. The default is seeded with a fixed constant, which makes hashing reproducible: two filters built with the default hasher are always mergeable, and serialized state round-trips byte-for-byte across runs. The trade-off is that a fixed seed offers no defence against an adversary who crafts inputs to collide on purpose. When the inputs are untrusted, substitute a randomly-seeded BuildHasher such as std::collections::hash_map::RandomState:

use std::collections::hash_map::RandomState;
use bloom_lib::BloomFilter;

let filter: BloomFilter<&str, RandomState> =
    BloomFilter::with_hasher(1_000, 0.01, RandomState::new()).unwrap();

Structs§

DefaultHashBuilder
A BuildHasher that yields DefaultHasher instances seeded with a fixed constant.
DefaultHasher
A fast, non-cryptographic 64-bit hasher with strong avalanche behaviour.