diff --git a/src/iterators/mod.rs b/src/iterators/mod.rs index 973d304..f8a2abe 100644 --- a/src/iterators/mod.rs +++ b/src/iterators/mod.rs @@ -186,7 +186,7 @@ where } // Have we already picked the index with the last non-zero count in the histogram? - if self.last_picked_index >= self.max_value_index { + if self.last_picked_index >= self.max_value_index && self.last_picked_index != 0 { // is the picker done? if !self.picker.more(self.current_index) { self.ended = true; diff --git a/tests/histogram.rs b/tests/histogram.rs index 9235eed..c9f07ef 100644 --- a/tests/histogram.rs +++ b/tests/histogram.rs @@ -560,3 +560,10 @@ fn subtract_underflow_guarded_by_per_value_count_check() { h.subtract(h2).unwrap_err() ); } + +#[test] +fn recorded_only_zeros() { + let mut h = Histogram::::new(1).unwrap(); + h += 0; + assert_eq!(h.iter_recorded().collect::>().len(), 1); +}