selectors: Add a simple Debug impl for CountingBloomFilter.

This commit is contained in:
Cameron McCormack 2017-08-09 13:59:37 +08:00
parent df2c8b2902
commit b23f947d77

View file

@ -6,6 +6,7 @@
//! for selector matching.
use fnv::FnvHasher;
use std::fmt::{self, Debug};
use std::hash::{Hash, Hasher};
// The top 8 bits of the 32-bit hash value are not used by the bloom filter.
@ -141,6 +142,18 @@ impl<S> CountingBloomFilter<S> where S: BloomStorage {
}
}
impl<S> Debug for CountingBloomFilter<S> where S: BloomStorage {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut slots_used = 0;
for i in 0..ARRAY_SIZE {
if !self.storage.slot_is_empty(i) {
slots_used += 1;
}
}
write!(f, "BloomFilter({}/{})", slots_used, ARRAY_SIZE)
}
}
pub trait BloomStorage : Clone + Default {
fn slot_is_empty(&self, index: usize) -> bool;
fn adjust_slot(&mut self, index: usize, increment: bool);