StableBloomFilter

Struct StableBloomFilter 

Source
pub struct StableBloomFilter { /* private fields */ }
Expand description

Stable bloom filter, the best choice for small data set. In this structure, k hash functions share a global bitmap, whose max size is u64::MAX. Usage:

use roaring_bloom_filter::*;

let mut bf = StableBloomFilter::new(100, 0.001_f64);

bf.add(&10);
bf.add(&'a');
bf.add(&"a string");

bf.contains(&12);

Stable Bloom Filter(SBF)

All hash function share the whole bitmap. Best choice for relatively small dataset.

Implementations§

Source§

impl StableBloomFilter

Source

pub fn from_scratch( hash_num: u32, bitmap_size: u64, target_false_positive_rate: f64, ) -> StableBloomFilter

Create an empty stable bloom filter from scratch.

Generally, user should not use this initializer directly. Promise the limitation on yourself:

  • 0 < k <= u32::MAX
  • 0 < m <= u32::MAX
  • 0 < f < 1
Source

pub fn new(max_size: u64, target_false_positive: f64) -> impl BloomFilter

Create an empty bloom filter with max element’s size and false positive rate. The crate would calculate the best hash number and bitmap size.

Trait Implementations§

Source§

impl BloomFilter for StableBloomFilter

Source§

fn add<T>(&mut self, value: &T) -> bool
where T: Hash,

Add new element into the bloom filter. Return true when any key are inserted in a slice.
Source§

fn contains<T>(&self, value: &T) -> bool
where T: Hash,

Check if the bloom filter contains the specific key. Return true when all key are present in all slices, which may contains false positive situation.
Source§

fn target_false_positive_rate(&self) -> f64

Get target false positive rate.
Source§

fn current_false_positive_rate(&self) -> f64

Get current false positive rate.
Source§

fn is_empty(&self) -> bool

If this bloom filter is empty.
Source§

fn is_full(&self) -> bool

If this bloom filter is full.
Source§

fn size(&self) -> u64

Get the number of inserted elements in this bloom filter.
Source§

fn len(&self) -> u64

Get the number of inserted bits in all slices.
Source§

impl Display for StableBloomFilter

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.