Skip to main content

BloomFilter

Struct BloomFilter 

Source
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

Source

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).

Source

pub fn insert(&mut self, key: &[u8])

Insert one key. Idempotent (re-inserting flips no bits).

Source

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).

Source

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.

Source

pub const fn num_hashes(&self) -> u32

Hash-count introspection.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> BloomFilter

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BloomFilter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.