Struct Bloom

Source
pub struct Bloom<T: ?Sized> { /* private fields */ }
Expand description

Bloom filter structure

Implementations§

Source§

impl<T: ?Sized> Bloom<T>

Source

pub fn new_with_seed( bitmap_size: usize, items_count: usize, seed: &[u8; 32], ) -> Result<Self, &'static str>

Create a new bloom filter structure. bitmap_size is the size in bytes (not bits) that will be allocated in memory items_count is an estimation of the maximum number of items to store. seed is a random value used to generate the hash functions.

Source

pub fn new(bitmap_size: usize, items_count: usize) -> Result<Self, &'static str>

Create a new bloom filter structure. bitmap_size is the size in bytes (not bits) that will be allocated in memory items_count is an estimation of the maximum number of items to store.

Source

pub fn new_for_fp_rate( items_count: usize, fp_p: f64, ) -> Result<Self, &'static str>

Create a new bloom filter structure. items_count is an estimation of the maximum number of items to store. fp_p is the wanted rate of false positives, in ]0.0, 1.0[

Source

pub fn new_for_fp_rate_with_seed( items_count: usize, fp_p: f64, seed: &[u8; 32], ) -> Result<Self, &'static str>

Create a new bloom filter structure. items_count is an estimation of the maximum number of items to store. fp_p is the wanted rate of false positives, in ]0.0, 1.0[

Source

pub fn compute_bitmap_size(items_count: usize, fp_p: f64) -> usize

Compute a recommended bitmap size for items_count items and a fp_p rate of false positives. fp_p obviously has to be within the ]0.0, 1.0[ range.

Source

pub fn len(&self) -> u64

Return the number of bits in the filter.

Source

pub fn set(&mut self, item: &T)
where T: Hash,

Record the presence of an item.

Source

pub fn check(&self, item: &T) -> bool
where T: Hash,

Check if an item is present in the set. There can be false positives, but no false negatives.

Source

pub fn check_and_set(&mut self, item: &T) -> bool
where T: Hash,

Record the presence of an item in the set, and return the previous state of this item.

Source

pub fn as_slice(&self) -> &[u8]

View the bloom filter as an opaque slice of bytes. This can be used to save the bloom filter to a file.

Source

pub fn from_slice(bytes: &[u8]) -> Result<Self, &'static str>

Create a bloom filter from a slice of bytes, previously generated with as_slice.

Source

pub fn to_bytes(&self) -> Vec<u8>

Serialize the bloom filter to an opaque byte vector.

Source

pub fn into_bytes(self) -> Vec<u8>

Transform the bloom filter into a byte vector.

Source

pub fn from_bytes(bytes: Vec<u8>) -> Result<Self, &'static str>

Transform a byte vector into a bloom filter.

Source

pub fn number_of_hash_functions(&self) -> u32

Return the number of hash functions used for check and set

Source

pub fn clear(&mut self)

Clear all of the bits in the filter, removing all keys from the set

Source

pub fn fill(&mut self)

Set all of the bits in the filter, making it appear like every key is in the set

Source

pub fn is_empty(&self) -> bool

Test if there are no elements in the set

Source

pub fn seed(&self) -> [u8; 32]

Return the seed used to generate the hash functions

Trait Implementations§

Source§

impl<T: Clone + ?Sized> Clone for Bloom<T>

Source§

fn clone(&self) -> Bloom<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: ?Sized> Debug for Bloom<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Bloom<T>
where T: ?Sized,

§

impl<T> RefUnwindSafe for Bloom<T>
where T: RefUnwindSafe + ?Sized,

§

impl<T> Send for Bloom<T>
where T: Send + ?Sized,

§

impl<T> Sync for Bloom<T>
where T: Sync + ?Sized,

§

impl<T> Unpin for Bloom<T>
where T: Unpin + ?Sized,

§

impl<T> UnwindSafe for Bloom<T>
where T: UnwindSafe + ?Sized,

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.