pub struct BloomFilter { /* private fields */ }Implementations§
Source§impl BloomFilter
impl BloomFilter
Sourcepub fn new(expected_items: usize, false_positive_rate: f64) -> Self
pub fn new(expected_items: usize, false_positive_rate: f64) -> Self
Create a new Bloom filter
- expected_items: number of items to be inserted
- false_positive_rate: desired false positive rate (e.g., 0.01 for 1%)
Sourcepub fn contains<T: Hash>(&self, item: &T) -> bool
pub fn contains<T: Hash>(&self, item: &T) -> bool
Check if an item might be in the set
Returns true if item might be present (could be false positive) Returns false if item is definitely not present (100% accurate)
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
Serialize to bytes with BLAKE3 checksum for corruption detection
CRITICAL FIX: Adds integrity checksum to detect bit flips, cosmic rays, disk errors, or malicious modification of bloom filter data.
Format v2 (with version header for forward compatibility):
- Magic number: 4 bytes (“BLM\x02” = 0x424C4D02)
- Header: num_bits (8) + num_hashes (8) + num_words (8) = 24 bytes
- Bit data: num_words * 8 bytes
- Checksum: 32 bytes (BLAKE3 hash of magic + header + data)
Format v1 (legacy, for backward compatibility):
- Header: num_bits (8) + num_hashes (8) + num_words (8) = 24 bytes
- Bit data: num_words * 8 bytes
- Checksum: 32 bytes
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self>
pub fn from_bytes(bytes: &[u8]) -> Result<Self>
Deserialize from bytes with checksum validation and version detection
CRITICAL FIX: Validates BLAKE3 checksum to detect bloom filter corruption. If corrupted, returns an error. The caller can then rebuild from the index.
FORWARD COMPATIBILITY: Detects format version via magic number.
- v2 (with magic “BLM\x02”): New format with version header
- v1 (no magic): Legacy format, auto-detected by size
Sourcepub fn from_bytes_legacy(bytes: &[u8]) -> Result<Self>
pub fn from_bytes_legacy(bytes: &[u8]) -> Result<Self>
Deserialize from bytes without checksum validation (for backward compatibility)
Use this for reading old bloom filters that don’t have checksums.
New bloom filters should use from_bytes() which validates checksums.
Sourcepub fn size_bytes(&self) -> usize
pub fn size_bytes(&self) -> usize
Get size in bytes
Sourcepub fn memory_size(&self) -> usize
pub fn memory_size(&self) -> usize
Get memory size (alias for size_bytes)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BloomFilter
impl RefUnwindSafe for BloomFilter
impl Send for BloomFilter
impl Sync for BloomFilter
impl Unpin for BloomFilter
impl UnsafeUnpin for BloomFilter
impl UnwindSafe for BloomFilter
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more