pub struct BloomFilter { /* private fields */ }Expand description
Bit-set Bloom filter with num_hashes independent bit positions
per key, derived from one FNV-1a hash + one SplitMix64-scrambled
secondary (Kirsch–Mitzenmacher double-hashing). Tunable via the
constructor’s (num_items, fp_rate) target.
Implementations§
Source§impl BloomFilter
impl BloomFilter
Sourcepub fn with_target_fp_rate(num_items: usize, fp_rate: f64) -> Self
pub fn with_target_fp_rate(num_items: usize, fp_rate: f64) -> Self
Build a Bloom sized to keep the false-positive rate at or
below fp_rate when populated with num_items distinct keys.
Sizes are derived from the standard formulas
m = -(n × ln(p)) / (ln 2)^2
k = ⌈m / n × ln 2⌉rounded so num_bits is a multiple of 64 (one u64 word per
bit-pack unit) and num_hashes is clamped to
[1, NUM_HASHES_MAX].
Constructor panics on num_items == 0 or fp_rate ∉ (0, 1)
— both indicate caller misuse, not a recoverable runtime
condition. v5 internal call sites always supply sane numbers
(segment row count + a configured target).
Sourcepub fn contains(&self, key: &[u8]) -> bool
pub fn contains(&self, key: &[u8]) -> bool
Probe one key. Returns true if every bit position derived
from the key is set — i.e. the key might be present;
false is a hard absence (no FP on negative).
Sourcepub const fn num_bits(&self) -> u64
pub const fn num_bits(&self) -> u64
Bit-count introspection — used by segment writer to size the envelope and by tests to assert FP-rate calculations.
Sourcepub const fn num_hashes(&self) -> u32
pub const fn num_hashes(&self) -> u32
Hash-count introspection.
Sourcepub fn encoded_len(&self) -> usize
pub fn encoded_len(&self) -> usize
Encoded byte length without actually building the buffer.
Header (4+8+4+4 = 20) + (num_bits / 8) body bytes.
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
Serialise to the v1 file format. Used by the segment writer to embed the bloom into a sidecar section of the segment envelope.
Sourcepub fn from_bytes(input: &[u8]) -> Result<Self, BloomError>
pub fn from_bytes(input: &[u8]) -> Result<Self, BloomError>
Parse from the v1 file format. Validates magic, shape,
num_hashes range, and CRC over the body before constructing
the value — any of those failing returns BloomError rather
than panicking.
Trait Implementations§
Source§impl Clone for BloomFilter
impl Clone for BloomFilter
Source§fn clone(&self) -> BloomFilter
fn clone(&self) -> BloomFilter
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more