#hash-table #bloom #open-addressing #double-hashing

hash-iter

Iterator producing sequence of hash values for a given input (using double hashing technique)

9 stable releases

2.0.1 Nov 5, 2025
2.0.0 Nov 4, 2025
1.2.2 Aug 10, 2025
1.2.1 Nov 29, 2024
0.1.0 Nov 7, 2024

#404 in Algorithms

Download history 500/week @ 2025-09-17 629/week @ 2025-09-24 299/week @ 2025-10-01 88/week @ 2025-10-08 5612/week @ 2025-10-15 32672/week @ 2025-10-22 30878/week @ 2025-10-29 48938/week @ 2025-11-05 36760/week @ 2025-11-12 17404/week @ 2025-11-19 14793/week @ 2025-11-26 14831/week @ 2025-12-03 8040/week @ 2025-12-10 7396/week @ 2025-12-17 3710/week @ 2025-12-24 1027/week @ 2025-12-31

21,598 downloads per month
Used in 2 crates

MIT license

17KB
182 lines

hash-iter

crates.io docs.rs unsafe forbidden dependencies

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 hash_iter::{DoubleHashHasher, HashIterHasher};

let hasher = DoubleHashHasher::new();
let hashes: Vec<u64> = hasher.hash_iter(&"key", 10).collect();

Usage

Basic Usage

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<_>>();

Configuration

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:

  • Seeds: 12345, 67890
  • Modulus n: T::MAX for the chosen type
  • Hash function: XXH3

Custom Hash Functions

Use 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<_>>();

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)/6 (mod n)

The implementation uses forward differencing for O(1) computation per iteration.

License

MIT

Dependencies

~105KB