pub struct Bloom<T: ?Sized> { /* private fields */ }
Expand description
Bloom filter structure
Implementations§
Source§impl<T: ?Sized> Bloom<T>
impl<T: ?Sized> Bloom<T>
Sourcepub fn new_with_seed(
bitmap_size: usize,
items_count: usize,
seed: &[u8; 32],
) -> Result<Self, &'static str>
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.
Sourcepub fn new(bitmap_size: usize, items_count: usize) -> Result<Self, &'static str>
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.
Sourcepub fn new_for_fp_rate(
items_count: usize,
fp_p: f64,
) -> Result<Self, &'static str>
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[
Sourcepub fn new_for_fp_rate_with_seed(
items_count: usize,
fp_p: f64,
seed: &[u8; 32],
) -> Result<Self, &'static str>
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[
Sourcepub fn compute_bitmap_size(items_count: usize, fp_p: f64) -> usize
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.
Sourcepub fn check(&self, item: &T) -> boolwhere
T: Hash,
pub fn check(&self, item: &T) -> boolwhere
T: Hash,
Check if an item is present in the set. There can be false positives, but no false negatives.
Sourcepub fn check_and_set(&mut self, item: &T) -> boolwhere
T: Hash,
pub fn check_and_set(&mut self, item: &T) -> boolwhere
T: Hash,
Record the presence of an item in the set, and return the previous state of this item.
Sourcepub fn as_slice(&self) -> &[u8] ⓘ
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.
Sourcepub fn from_slice(bytes: &[u8]) -> Result<Self, &'static str>
pub fn from_slice(bytes: &[u8]) -> Result<Self, &'static str>
Create a bloom filter from a slice of bytes, previously generated with as_slice
.
Sourcepub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
Transform the bloom filter into a byte vector.
Sourcepub fn from_bytes(bytes: Vec<u8>) -> Result<Self, &'static str>
pub fn from_bytes(bytes: Vec<u8>) -> Result<Self, &'static str>
Transform a byte vector into a bloom filter.
Sourcepub fn number_of_hash_functions(&self) -> u32
pub fn number_of_hash_functions(&self) -> u32
Return the number of hash functions used for check
and set