MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / bloom_bit_pos

Function bloom_bit_pos

nodedb-columnar/src/predicate.rs:386–395  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

384/// produce independent bit positions. `m` must be a power of two so the
385/// bitmask `m - 1` is exact.
386fn 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`.
398pub fn bloom_insert(bloom: &mut BloomFilter, value: &str) {

Callers 2

bloom_insertFunction · 0.85
bloom_may_containFunction · 0.85

Calls 1

bytesMethod · 0.45

Tested by

no test coverage detected