Struct BloomFilter

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

A Bloom filter is a space-efficient probabilistic data structure, conceived by Burton Howard Bloom in 1970, that is used to test whether an element is a member of a set. False positive matches are possible, but false negatives are not.

Reference: Bloom, B. H. (1970). Space/time trade-offs in hash coding with allowable errors. Communications of the ACM, 13(7), 422-426. Full text article

Implementations§

Source§

impl BloomFilter

Source

pub fn new(config: FilterBuilder) -> Self

Build a Bloom filter form FilterBuilder.

§Examples:
use fastbloom_rs::{BloomFilter, FilterBuilder};

let builder = FilterBuilder::new(100_000_000, 0.01);
let bloom = BloomFilter::new(builder);
Source

pub fn add_if_not_contains(&mut self, element: &[u8]) -> bool

Tests whether an element is present in the filter (subject to the specified false positive rate). And if it is not in this filter, add it to the filter.

Source

pub fn from_file_with_hashes(path: &str) -> Self

Build a Bloom filter from file with first four bytes is hashes which is encode by big-endian. The remaining is underlying byte vector of the Bloom filter.

Source

pub fn from_file(path: &str, hashes: u32) -> Self

Build a Bloom filter from file. The content is underlying byte vector of the Bloom filter.

Source

pub fn from_u8_array(array: &[u8], hashes: u32) -> Self

Build a Bloom filter form &[u8].

§Examples
use fastbloom_rs::BloomFilter;
let mut array = vec![0u8; 4096];
let bloom = BloomFilter::from_u8_array(array.as_bytes(), 4);
Source

pub fn from_u16_array(array: &[u16], hashes: u32) -> Self

Build a Bloom filter form &[u16].

§Examples
use fastbloom_rs::BloomFilter;
let mut array = vec![0u16; 2048];
let bloom = BloomFilter::from_u16_array(array.as_bytes(), 4);
Source

pub fn from_u32_array(array: &[u32], hashes: u32) -> Self

Build a Bloom filter form &[u32].

§Examples
use fastbloom_rs::BloomFilter;
let mut array = vec![0u32; 1024];
let bloom = BloomFilter::from_u32_array(array.as_bytes(), 4);
Source

pub fn from_u64_array(array: &[u64], hashes: u32) -> Self

Build a Bloom filter form &[u64].

§Examples
use fastbloom_rs::BloomFilter;
let mut array = vec![0u64; 512];
let bloom = BloomFilter::from_u32_array(array.as_bytes(), 4);
Source

pub fn config(&self) -> FilterBuilder

Returns the configuration/builder of the Bloom filter.

§Examples
use fastbloom_rs::{BloomFilter, FilterBuilder};

let bloom = FilterBuilder::new(100_000_000, 0.01).build_bloom_filter();
let builder = bloom.config();
Source

pub fn save_to_file_with_hashes(&mut self, path: &str)

Save the bloom filter to file, and the first four bytes is hashes with big-endian, and the remaining bytes is underlying byte vector of the Bloom filter.

Source

pub fn save_to_file(&mut self, path: &str)

Save the bloom filter to file, and the content of the file is underlying byte vector of the Bloom filter.

Source

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

Return the underlying byte vector of the Bloom filter.

Source

pub fn get_u16_array(&self) -> &[u16]

Return the underlying u16 vector of the Bloom filter.

Source

pub fn get_u32_array(&self) -> &[u32]

Return the underlying u32 vector of the Bloom filter.

Source

pub fn get_u64_array(&self) -> &[u64]

Return the underlying u64 vector of the Bloom filter.

Source

pub fn union(&mut self, other: &BloomFilter) -> bool

Performs the union operation on two compatible bloom filters. This is achieved through a bitwise OR operation on their bit vectors. This operations is lossless, i.e. no elements are lost and the bloom filter is the same that would have resulted if all elements wer directly inserted in just one bloom filter.

Source

pub fn intersect(&mut self, other: &BloomFilter) -> bool

Performs the intersection operation on two compatible bloom filters. This is achieved through a bitwise AND operation on their bit vectors. The operations doesn’t introduce any false negatives but it does raise the false positive probability. The the false positive probability in the resulting Bloom filter is at most the false-positive probability in one of the constituent bloom filters

Source

pub fn is_empty(&self) -> bool

Returns true if the Bloom filter does not contain any elements

Source

pub fn estimate_set_cardinality(&self) -> f64

Trait Implementations§

Source§

impl Clone for BloomFilter

Source§

fn clone(&self) -> BloomFilter

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

const 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
Source§

impl Hashes for BloomFilter

Source§

fn hashes(&self) -> u32

Returns the hash function number of the Bloom filter.

Source§

impl Membership for BloomFilter

Source§

fn add(&mut self, element: &[u8])

Adds the passed value to the filter.

Source§

fn contains(&self, element: &[u8]) -> bool

Tests whether an element is present in the filter (subject to the specified false positive rate).

Source§

fn get_hash_indices(&self, element: &[u8]) -> Vec<u64>

Get the hashes indices of the element in the filter.

Source§

fn contains_hash_indices(&self, indices: &Vec<u64>) -> bool

Tests whether a hashes indices is present in the filter

Source§

fn clear(&mut self)

Removes all elements from the filter (i.e. resets all bits to zero).

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.