From b23f947d77e4299f547994ead9b5c703c37fa070 Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Wed, 9 Aug 2017 13:59:37 +0800 Subject: [PATCH] selectors: Add a simple Debug impl for CountingBloomFilter. --- components/selectors/bloom.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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);