Skip to main content

BloomPrescreen

Struct BloomPrescreen 

Source
pub struct BloomPrescreen {
    pub bits: Vec<u64>,
    pub k_hashes: u32,
    pub num_bits: usize,
    /* private fields */
}
Expand description

Bloom filter optimised for deduplication pre-screening.

§Example

use oximedia_dedup::bloom_prescreen::BloomPrescreen;

let mut bp = BloomPrescreen::new(1000, 0.01);
bp.insert(b"hello");
assert!(bp.might_contain(b"hello"));
assert!(!bp.might_contain(b"world")); // (with high probability)

Fields§

§bits: Vec<u64>

Underlying bit storage (each u64 holds 64 bits).

§k_hashes: u32

Number of independent hash functions.

§num_bits: usize

Total number of addressable bits.

Implementations§

Source§

impl BloomPrescreen

Source

pub fn new(capacity: usize, false_positive_rate: f64) -> Self

Create a new BloomPrescreen sized for capacity expected items at the given false_positive_rate.

Uses the standard formulas:

  • m = ceil(-n * ln(p) / (ln 2)^2) (number of bits)
  • k = round((m / n) * ln 2) (number of hash functions)

Both values are clamped to sensible minimums.

Source

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

Insert key into the filter.

After calling this, might_contain will always return true for the same key (no false negatives).

Source

pub fn might_contain(&self, key: &[u8]) -> bool

Returns true if key might be in the set (possible false positive). Returns false if key is definitely not in the set.

Source

pub fn false_positive_rate_estimate(&self) -> f64

Estimate the current false-positive rate given the number of inserted items.

Formula: (1 - e^(-k * n / m))^k

Returns 1.0 when the filter is full.

Source

pub fn items_inserted(&self) -> u64

Number of items inserted so far.

Source

pub fn clear(&mut self)

Reset the filter to its initial empty state.

Source

pub fn set_bit_count(&self) -> u64

Number of set bits (useful for diagnostics).

Trait Implementations§

Source§

impl Clone for BloomPrescreen

Source§

fn clone(&self) -> BloomPrescreen

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 BloomPrescreen

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.