mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
selectors: Add a simple Debug impl for CountingBloomFilter.
This commit is contained in:
parent
df2c8b2902
commit
b23f947d77
1 changed files with 13 additions and 0 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue