Struct cbloom::Filter
[−]
[src]
pub struct Filter { /* fields omitted */ }
A concurrent Bloom filter.
Bloom filters are a probabilistic data structure, which allows you to insert elements, and later test if they were inserted. The filter will either know it doesn't contain the element, or that it might. It will never be "sure", hence the name "filter".
It works by having an array of bits. Every element is hashed into a sequence of these bits. The bits of the inserted elements are set to 1. When testing for membership, we simply AND the bits.
Methods
impl Filter
[src]
fn new(bytes: usize, expected_elements: usize) -> Filter
Create a new Bloom filter with the optimal number of hash functions.
This creates a Bloom filter with bytes
bytes of internal data, and optimal number (for
expected_elements
number of elements) of hash functions.
fn with_size_and_hashers(bytes: usize, hashers: usize) -> Filter
Create a new Bloom filter with some number of bytes and hashers.
This creates a Bloom filter with at least bytes
bytes of internal data and hashers
number of hash functions.
If hashers
is 0, it will be rounded to 1.
fn clear(&self)
Clear the Bloom filter.
This removes every element from the Bloom filter.
Note that it will not do so atomically, and it can remove elements inserted simulatenously to this function being called.
fn insert(&self, x: u64)
Insert an element into the Bloom filter.
fn maybe_contains(&self, x: u64) -> bool
Check if the Bloom filter potentially contains an element.
This returns true
if we're not sure if the filter contains x
or not, and false
if we
know that the filter does not contain x
.