diff --git a/components/selectors/bloom.rs b/components/selectors/bloom.rs index 9475676ec71..2b96e4f51f8 100644 --- a/components/selectors/bloom.rs +++ b/components/selectors/bloom.rs @@ -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 CountingBloomFilter where S: BloomStorage { } } +impl Debug for CountingBloomFilter 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);