Bloomfilter

Struct Bloomfilter 

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

Bloom Filter

Implementations§

Source§

impl Bloomfilter

Source

pub fn new(n_bits: usize, n_hash_functions: usize) -> Self

Get a new bloom filter with a bitmap of length n_bits and n_hash_functions hash functions.

§Arguments
  • n_bits: How many bits should the bitmap of the bloomfilter have? More bits make collision (False Positives) more unlikely.

  • n_hash_functions: How many hash functions should be used?

§Examples
use bloomfilter_rs::filter;

let bloom_filter = filter::Bloomfilter::new(
    10,
    20
);
Source

pub fn new_with_seeds(n_bits: usize, seeds: Vec<u64>) -> Self

Generate a bloomfilter with non-random seeds.

§Arguments
  • n_bits: How many bits should the bitmap of the bloomfilter have? More bits make collision (False Positives) more unlikely.

  • seeds: Provide custom seeds to parameterize the hash functions. Given a different seed, the hash function would hash the same objects to different hashes. You should not provide the same seeds twice.

§Examples
use bloomfilter_rs::filter;

let bloom_filter = filter::Bloomfilter::new_with_seeds(
    10,
    vec![1, 10, 100],
);
Source

pub fn new_with_seeds_and_custom_hash_function( n_bits: usize, seeds: Vec<u64>, hash_function: fn(&[u8], u64) -> u64, ) -> Self

Generate a bloomfilter with non-random seeds and a custom hash function.

§Arguments
  • n_bits: How many bits should the bitmap of the bloomfilter have? More bits make collision (False Positives) more unlikely.

  • seeds: Provide custom seeds to parameterize the hash functions. Given a different seed, the hash function would hash the same objects to different hashes. You should not provide the same seeds twice.

  • hash_function: Specify a custom hash function. Hash functions should take in the bytes of the data and a seed to parmetrize the behaviour of the hash function. Given different hash values the function should show different behaviour.

§Examples
use bloomfilter_rs::filter;

let bloom_filter = filter::Bloomfilter::new_with_seeds_and_custom_hash_function(
    10,
    vec![1, 10, 100],
    |bytes, seed| -> u64
        {(bytes.iter().map(|elem| *elem as u64).sum::<u64>() + seed).into()}
);
Source

pub fn from_specification( expected_number_of_entries: usize, acceptable_false_positive_rate: f64, ) -> Self

Create a random bloomfilter given its supposed characteristics.

Give the number of expected entries and the acceptable false positive rates, we can create a hashfilter that will have the expected characteristic. If we use more entries then expected, the false positive rate might decrease.

§Arguments:
  • expected_nubmber_of_entries: How many entries do you expect in the hash filter?
  • acceptable_false_positive_rate: What false positive rate is acceptabel for your use-case?
§Examples
use bloomfilter_rs::filter;

let my_hash_filter = filter::Bloomfilter::from_specification(10, 0.5);
Source

pub fn number_of_bits(&self) -> usize

How many bits does the bitmap of the filter have?

§Examples
use bloomfilter_rs::filter;

let bloom_filter = filter::Bloomfilter::new(
    10,
    20
);
println!("{}", bloom_filter.number_of_bits())
Source

pub fn insert(&mut self, object_as_string: &str)

Insert an object into the bloomfilter. The object should be a string.

If you map higher-level objects (struct ect.) to string, make sure that the representation does exactly identify each object (e.g. two different objects cannot map to the same string representation).

§Arguments
  • object: The object to insert.
§Examples
use bloomfilter_rs::filter;

let mut bloom_filter = filter::Bloomfilter::new(
    10,
    20,
);
bloom_filter.insert("To be inserted");
Source

pub fn insert_object_as_bytes(&mut self, object_as_bytes: &[u8])

Insert an object as bytes into the bloomfilter.

§Arguments
  • object_as_bytes: The object to insert.
§Examples
use bloomfilter_rs::filter;

let mut bloom_filter = filter::Bloomfilter::new(
    10,
    20,
);
bloom_filter.insert_object_as_bytes("To be inserted".as_bytes());
Source

pub fn contains(&self, object_as_string: &str) -> bool

Test that an object is in the hash filter. The objects needs to be string.

The bloomfilter is probabilistic in nature. False negatives cannot occur (if bloomfilter.contains returns false, that will always be true), but false positives can occur.

§Arguments
  • object_as_string: The object to check if it is contained in the bloomfilter.
§Examples
use bloomfilter_rs::filter;

let mut bloom_filter = filter::Bloomfilter::new(
    10,
    20,
);
bloom_filter.contains("To be inserted");
Source

pub fn contains_object_as_bytes(&self, object_as_bytes: &[u8]) -> bool

Test that an object as byte-array is in the hash filter.

§Arguments
  • object_as_bytes: The object to check if it is contained in the bloomfilter.
§Examples
use bloomfilter_rs::filter;

let mut bloom_filter = filter::Bloomfilter::new(
    10,
    20,
);
bloom_filter.contains_object_as_bytes("To be inserted".as_bytes());

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, 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V