| Crates.io | hash-iter |
| lib.rs | hash-iter |
| version | 2.0.1 |
| created_at | 2024-11-07 20:59:02.804709+00 |
| updated_at | 2025-11-05 10:12:01.437575+00 |
| description | Iterator producing sequence of hash values for a given input (using double hashing technique) |
| homepage | https://github.com/farazdagi/hash-iter |
| repository | https://github.com/farazdagi/hash-iter |
| max_upload_size | |
| id | 1440181 |
| size | 51,707 |
Implementation of the enhanced double hashing technique based on the Bloom Filters in Probabilistic Verification paper (Dillinger and Manolios, 2004).
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.
use hash_iter::{DoubleHashHasher, HashIterHasher};
let hasher = DoubleHashHasher::new();
let hashes: Vec<u64> = hasher.hash_iter(&"key", 10).collect();
Hash a key to generate a sequence of hash values:
use hash_iter::{DoubleHashHasher, HashIterHasher};
let hasher = DoubleHashHasher::new();
// Generate 3 hash values for each key
let hashes = hasher.hash_iter(&"foo", 3).collect::<Vec<_>>();
let hashes = hasher.hash_iter(&"bar", 3).collect::<Vec<_>>();
Customize the hasher with seeds, modulus, and output type:
use hash_iter::{BuildHashIterHasher, DoubleHashBuilder, HashIterHasher};
// Configure for u32 with custom parameters
let hasher = DoubleHashBuilder::<u32>::new()
.with_seed1(12345)
.with_seed2(67890)
.with_n(10000) // Maximum hash value
.build_hash_iter_hasher();
let hashes: Vec<u32> = hasher.hash_iter(&"key", 5).collect();
Default configuration:
12345, 67890n: T::MAX for the chosen typeUse any hash function implementing std::hash::BuildHasher:
use hash_iter::{DoubleHashHasher, HashIterHasher};
use xxhash_rust::xxh3::Xxh3Builder;
let hasher = DoubleHashHasher::<u64, _, _>::with_hash_builders(
Xxh3Builder::new().with_seed(111),
Xxh3Builder::new().with_seed(222),
u64::MAX,
);
let hashes = hasher.hash_iter(&"hello", 3).collect::<Vec<_>>();
This crate enables efficient implementations of hash-based algorithms:
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.
MIT