diff --git a/libraries/persistent_store/fuzz/src/histogram.rs b/libraries/persistent_store/fuzz/src/histogram.rs index 0d76fd7..8237055 100644 --- a/libraries/persistent_store/fuzz/src/histogram.rs +++ b/libraries/persistent_store/fuzz/src/histogram.rs @@ -33,12 +33,7 @@ impl Histogram { /// /// The bucket of `item` is the highest power of two, lower or equal to `item`. If `item` is /// zero, then its bucket is also zero. - /// - /// # Panics - /// - /// Panics if the item is too big, i.e. it uses its most significant bit. pub fn add(&mut self, item: usize) { - assert!(item <= usize::max_value() / 2); *self.buckets.entry(get_bucket(item)).or_insert(0) += 1; } @@ -49,15 +44,12 @@ impl Histogram { } } - /// Returns one past the highest non-empty bucket. + /// Returns the bit-width of one past the highest non-empty bucket. /// - /// In other words, all non-empty buckets of the histogram are smaller than the returned bucket. - pub fn bucket_lim(&self) -> usize { - match self.buckets.keys().max() { - None => 0, - Some(0) => 1, - Some(x) => 2 * x, - } + /// In other words, all non-empty buckets of the histogram have a bit-width smaller than the + /// returned width. + pub fn width_lim(&self) -> usize { + self.buckets.keys().max().map_or(0, |&x| num_bits(x) + 1) } /// Returns the count of a bucket. diff --git a/libraries/persistent_store/fuzz/src/stats.rs b/libraries/persistent_store/fuzz/src/stats.rs index fdb5983..7bef07e 100644 --- a/libraries/persistent_store/fuzz/src/stats.rs +++ b/libraries/persistent_store/fuzz/src/stats.rs @@ -17,7 +17,6 @@ //! This is not used during actual fuzzing, only when replaying a corpus to compute statistics. use crate::histogram::{bucket_from_width, Histogram}; -use crate::num_bits; use std::collections::HashMap; use strum::{Display, EnumIter, EnumString, IntoEnumIterator}; @@ -110,13 +109,14 @@ impl Stats { self.stats.get(&key).and_then(|h| h.get(bucket)) } - /// Returns one past the highest non-empty bucket. + /// Returns the bit-width of one past the highest non-empty bucket. /// - /// In other words, all non-empty buckets of the histogram are smaller than the returned bucket. - fn bucket_lim(&self) -> usize { + /// In other words, all non-empty buckets of the histogram have a bit-width smaller than the + /// returned width. + fn width_lim(&self) -> usize { self.stats .values() - .map(|h| h.bucket_lim()) + .map(|h| h.width_lim()) .max() .unwrap_or(0) } @@ -125,10 +125,10 @@ impl Stats { impl std::fmt::Display for Stats { fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> { let mut matrix: Vec> = Vec::new(); + let bits = self.width_lim(); let mut header = Vec::new(); header.push(String::new()); - let bits = num_bits(self.bucket_lim()); for width in 0..bits { header.push(format!(" {}", bucket_from_width(width))); }