pub struct Filter { /* private fields */ }Expand description
A split block bloom filter that handles it’s own memory
Implementations§
Source§impl Filter
impl Filter
Sourcepub fn new(bits_per_key: usize, num_keys: usize) -> Self
pub fn new(bits_per_key: usize, num_keys: usize) -> Self
Create a new filter using the parameters.
Calculated length will be rounded up to the nearest multiple of BUCKET_SIZE
bits_per_key can be used to adjust the false positive rate.
Some info can be found here.
num_keys means the number of unique hashes that are expected to be inserted to this bloom filter.
Sourcepub fn contains_hash(&self, hash: u64) -> bool
pub fn contains_hash(&self, hash: u64) -> bool
Check if the filter contains the hash.
Sourcepub fn insert_hash(&mut self, hash: u64) -> bool
pub fn insert_hash(&mut self, hash: u64) -> bool
Insert the hash into the filter.
Returns true if the hash was already in the filter.
Sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Returns the slice of bytes that represent this filter.
The filter can be restored using these bytes with the Filter::from_bytes method.
Sourcepub fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
pub fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
Returns a mutable reference to the slice of bytes that represent this filter.
This can be used to directly read into the filter from a file
Sourcepub fn from_bytes(bytes: &[u8]) -> Option<Self>
pub fn from_bytes(bytes: &[u8]) -> Option<Self>
Restore a filter from the given bytes.
Returns None if the bytes are invalid.