Skip to content

Commit

Permalink
fix: remove items from ExceptionalItems too
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-wright committed Jan 21, 2023
1 parent c17e7eb commit 69f74a4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
14 changes: 13 additions & 1 deletion src/cuckoo_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ impl CuckooFilter {
.buckets
.index(i0 as u64 ^ crate::hash(hasher, &fingerprint));

let removed = if self.buckets.contains(i0, fingerprint) {
let removed = if self.exceptional_items.contains(i0, i1, fingerprint) {
self.exceptional_items.remove(i0, i1, fingerprint)
} else if self.buckets.contains(i0, fingerprint) {
self.buckets.remove_fingerprint(i0, fingerprint)
} else if self.buckets.contains(i1, fingerprint) {
self.buckets.remove_fingerprint(i1, fingerprint)
Expand Down Expand Up @@ -218,4 +220,14 @@ impl ExceptionalItems {
}
self.0.push(item);
}

#[inline]
fn remove(&mut self, i0: usize, i1: usize, fingerprint: u64) -> bool {
let item = (fingerprint, cmp::min(i0, i1));
if let Ok(index) = self.0.binary_search(&item) {
self.0.remove(index);
return true;
}
false
}
}
7 changes: 1 addition & 6 deletions src/scalable_cuckoo_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl<T: Hash + ?Sized, H: Hasher + Clone, R: Rng> ScalableCuckooFilter<T, H, R>
f.shrink_to_fit(&self.hasher, &mut self.rng);
}
}

/// Removes `item` from this filter.
pub fn remove(&mut self, item: &T) {
let item_hash = crate::hash(&self.hasher, item);
Expand Down Expand Up @@ -310,11 +310,6 @@ mod test {
for i in 0..10_000 {
filter.remove(&i);
assert!(!filter.contains(&i));
//assert!(!filter.contains(&i));
//println!("{}", i);
//if filter.contains(&i) {
// println!("{i}");
//}
}
}

Expand Down

0 comments on commit 69f74a4

Please sign in to comment.