Skip to main content

default_hash_function

Function default_hash_function 

Source
pub fn default_hash_function(
    item: &[u8],
    num_hashes: usize,
    capacity: usize,
) -> Vec<u32>
Expand description

Implements the default double-hashing scheme for Bloom filters.

This function uses a technique called “double hashing” to generate multiple hash values from just two independent hash functions. It’s more efficient than computing completely separate hash functions for each index.

The formula used is: h(i) = (h1 + i * h2) mod capacity Where:

  • h1 is the first hash value (Murmur3)
  • h2 is the second hash value (FNV)
  • i ranges from 0 to num_hashes-1
  • capacity is the size of the bit vector

This approach provides good distribution while being computationally efficient. The wrapping operations prevent integer overflow on large values.

Parameters:

  • item: The byte slice to hash
  • num_hashes: The number of hash values to generate
  • capacity: The size of the bit vector (used for modulo)

Returns: A vector of num_hashes hash values, each in the range [0, capacity-1]