Compute the i-th hash slot for a string value in an `m`-bit filter. Uses FNV-1a seeded with different constants for each hash function to produce independent bit positions. `m` must be a power of two so the bitmask `m - 1` is exact.
(value: &str, hash_idx: u32, m: u32)
| 384 | /// produce independent bit positions. `m` must be a power of two so the |
| 385 | /// bitmask `m - 1` is exact. |
| 386 | fn bloom_bit_pos(value: &str, hash_idx: u32, m: u32) -> usize { |
| 387 | // Mix the hash index into the seed to produce distinct hash functions. |
| 388 | let mut hash = FNV_OFFSET ^ (hash_idx as u64).wrapping_mul(FNV_PRIME); |
| 389 | for byte in value.bytes() { |
| 390 | hash ^= byte as u64; |
| 391 | hash = hash.wrapping_mul(FNV_PRIME); |
| 392 | } |
| 393 | // Map to [0, m). m is always a power of two so (m - 1) is a valid mask. |
| 394 | (hash as usize) & ((m as usize) - 1) |
| 395 | } |
| 396 | |
| 397 | /// Insert a string value into a `BloomFilter`. |
| 398 | pub fn bloom_insert(bloom: &mut BloomFilter, value: &str) { |
no test coverage detected