Skip to content

Commit

Permalink
add: missing getters in v1 and v2 filters
Browse files Browse the repository at this point in the history
Signed-off-by: qjerome <qjerome@rawsec.lu>
  • Loading branch information
qjerome committed Apr 30, 2024
1 parent 717d852 commit 0c28b4c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
13 changes: 8 additions & 5 deletions poppy/src/bloom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ impl BloomFilter {
#[inline(always)]
pub fn capacity(&self) -> usize {
match self {
Self::V1(b) => b.capacity as usize,
Self::V2(b) => b.capacity as usize,
Self::V1(b) => b.capacity(),
Self::V2(b) => b.capacity(),
}
}

Expand All @@ -349,8 +349,8 @@ impl BloomFilter {
#[inline(always)]
pub fn fpp(&self) -> f64 {
match self {
Self::V1(b) => b.fpp,
Self::V2(b) => b.fpp,
Self::V1(b) => b.fpp(),
Self::V2(b) => b.fpp(),
}
}

Expand All @@ -374,7 +374,10 @@ impl BloomFilter {

/// Returns true if the filter is full
pub fn is_full(&self) -> bool {
self.count_estimate() as usize == self.capacity()
match self {
Self::V1(b) => b.is_full(),
Self::V2(b) => b.is_full(),
}
}

/// Returns the blob of data joined to the filter
Expand Down
16 changes: 16 additions & 0 deletions poppy/src/bloom/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,22 @@ impl BloomFilter {
self.bitset.len() * core::mem::size_of::<u64>()
}

#[inline(always)]
pub fn fpp(&self) -> f64 {
self.fpp
}

#[inline(always)]
pub fn capacity(&self) -> usize {
self.capacity as usize
}

#[inline(always)]
/// Returns true if the filter is full
pub fn is_full(&self) -> bool {
self.count_estimate() as usize == self.capacity()
}

#[inline(always)]
pub fn has_same_params(&self, other: &Self) -> bool {
self.flags == other.flags
Expand Down
16 changes: 16 additions & 0 deletions poppy/src/bloom/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,22 @@ impl BloomFilter {
self.buckets.len() * Bucket::byte_size() + self.index_cache.byte_len()
}

#[inline(always)]
pub fn fpp(&self) -> f64 {
self.fpp
}

#[inline(always)]
pub fn capacity(&self) -> usize {
self.capacity as usize
}

#[inline(always)]
/// Returns true if the filter is full
pub fn is_full(&self) -> bool {
self.count_estimate() as usize == self.capacity()
}

/// this function estimates the number of common elements between two bloom filters
/// without having to intersect them
pub fn count_common_entries(&self, other: &Self) -> Result<usize, Error> {
Expand Down

0 comments on commit 0c28b4c

Please sign in to comment.