hash-iter
Implementation of the enhanced double hashing technique based on the Bloom Filters in Probabilistic Verification paper (Dillinger and Manolios, 2004).
Motivation
Given a key key, instead of hashing it to a single value, one can hash it to a sequence of k hashes [hash_1, hash_2, .., hash_k].
See use cases below for details.
Quick Start
use ;
let hasher = new;
let hashes: = hasher.hash_iter.collect;
Usage
Basic Usage
Hash a key to generate a sequence of hash values:
use ;
let hasher = new;
// Generate 3 hash values for each key
let hashes = hasher.hash_iter.;
let hashes = hasher.hash_iter.;
Configuration
Customize the hasher with seeds, modulus, and output type:
use ;
// Configure for u32 with custom parameters
let hasher = new
.with_seed1
.with_seed2
.with_n // Maximum hash value
.build_hash_iter_hasher;
let hashes: = hasher.hash_iter.collect;
Default configuration:
- Seeds:
12345,67890 - Modulus
n:T::MAXfor the chosen type - Hash function: XXH3
Custom Hash Functions
Use any hash function implementing std::hash::BuildHasher:
use ;
use Xxh3Builder;
let hasher = with_hash_builders;
let hashes = hasher.hash_iter.;
Use Cases
This crate enables efficient implementations of hash-based algorithms:
- Bloom filters - Generate multiple filter positions from a single key (Kirsch and Mitzenmacher, 2006)
- Hash tables - Double hashing for collision resolution in open addressing
- Consistent hashing - Map keys to server rings (e.g., mpchash)
Instead of computing k independent hashes, double hashing produces k hash values from just two base hashes using the formula:
h(i) = h₁(key) + i·h₂(key) + (i³-i)/6 (mod n)
The implementation uses forward differencing for O(1) computation per iteration.
Documentation
- API Documentation - Full API reference
- Algorithm Paper - Enhanced double hashing technique
- Implementation Guide - Detailed architecture and development notes
License
MIT