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

Function build_bloom_with_params

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

Build a `BloomFilter` with explicit `k` (hash function count) and `m` (bit-array size). `m` must be a power of two and at least 8. This is useful when tuning the filter for a specific target false-positive rate. Use `build_bloom` for the standard default parameters.

(values: &[&str], k: u8, m: u32)

Source from the content-addressed store, hash-verified

442/// This is useful when tuning the filter for a specific target false-positive
443/// rate. Use `build_bloom` for the standard default parameters.
444pub fn build_bloom_with_params(values: &[&str], k: u8, m: u32) -> BloomFilter {
445 debug_assert!(
446 m >= 8 && m.is_power_of_two(),
447 "m must be a power of two ≥ 8"
448 );
449 let byte_count = (m as usize).div_ceil(8);
450 let mut bloom = BloomFilter {
451 k,
452 m,
453 bytes: vec![0u8; byte_count],
454 };
455 for v in values {
456 bloom_insert(&mut bloom, v);
457 }
458 bloom
459}
460
461#[cfg(test)]
462mod tests {

Calls 1

bloom_insertFunction · 0.85