[−][src]Struct bloom2::CompressedBitmap
CompressedBitmap implements a sparse, 2 level bloom filter - a space efficient, probabilistic set.
Users of a CompressedBitmap call
insert_hash
with deterministic, unique
hashes (a fingerprint) of their entries and check the existence of the entry
by calling contains_hash
.
use bloom2::{CompressedBitmap, FilterSize}; let mut filter = CompressedBitmap::new(FilterSize::KeyBytes2); let data_hashes = vec![ "bananas", "batman", "bintang", ]; for v in data_hashes.iter() { filter.insert_hash(v); } assert_eq!(filter.contains_hash("bananas"), true); assert_eq!(filter.contains_hash("apples"), false);
The CompressedBitmap maintains the same false-positive properties and similar performance properties as a normal bloom filter while lazily initialising the backing memory as it is needed, resulting in smaller memory footprints for all except completely loaded filters.
Insertions are amortised O(1)
and lookups are always O(1)
. The backing
memory is lazily initialised by growing a std::vec::Vec
, therefore it
uses the same (undefined) allocation strategy to amortise the expansion of
the backing memory - call shrink_to_fit
to reduce the underlying memory allocation to the minimum required.
Methods
impl CompressedBitmap
[src]
pub fn new(key_byte_size: FilterSize) -> Self
[src]
Initialises a new, empty bloom filter configured to consume hashes in
chunks of key_byte_size
number of bytes to use as keys.
pub fn shrink_to_fit(&mut self)
[src]
Reduces the allocated memory usage of the filter to the minimum required for the current filter contents.
This is useful to minimise the memory footprint of a populated, read-only CompressedBitmap.
See Vec::shrink_to_fit
.
pub fn clear(&mut self)
[src]
Resets the state of the filter.
An efficient way to remove all elements in the filter to allow it to be reused. Does not shrink the allocated backing memory, instead retaining the capacity to avoid reallocations.
pub fn insert_hash<T: AsRef<[u8]>>(&mut self, hash: T)
[src]
Inserts hash into the filter, chunking it into the configured key size.
Calling insert_hash
with a hash length greater than the configured key
size effectively increases the "hash" count, or k
property of the
filter.
pub fn contains_hash<T: AsRef<[u8]>>(&self, hash: T) -> bool
[src]
Checks if hash exists in the filter.
If contains_hash
returns true, hash
has probably been inserted
previously. If contains_hash
returns false, hash
has definitely
not been inserted into the filter.
Trait Implementations
impl Clone for CompressedBitmap
[src]
fn clone(&self) -> CompressedBitmap
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Auto Trait Implementations
impl RefUnwindSafe for CompressedBitmap
impl Send for CompressedBitmap
impl Sync for CompressedBitmap
impl Unpin for CompressedBitmap
impl UnwindSafe for CompressedBitmap
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,