Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #124 Record iteration when recording only zeros #125

Merged
merged 3 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/iterators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub struct HistogramIterator<'a, T: 'a + Counter, P: PickyIterator<T>> {
count_since_last_iteration: u64,
count_at_index: T,
current_index: usize,
last_picked_index: usize,
last_picked_index: Option<usize>,
max_value_index: usize,
fresh: bool,
ended: bool,
Expand Down Expand Up @@ -152,7 +152,7 @@ impl<'a, T: Counter, P: PickyIterator<T>> HistogramIterator<'a, T, P> {
count_since_last_iteration: 0,
count_at_index: T::zero(),
current_index: 0,
last_picked_index: 0,
last_picked_index: None,
max_value_index: h.index_for(h.max()).expect("Either 0 or an existing index"),
picker,
fresh: true,
Expand Down Expand Up @@ -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 >= Some(self.max_value_index) {
// is the picker done?
if !self.picker.more(self.current_index) {
self.ended = true;
Expand Down Expand Up @@ -243,7 +243,7 @@ where
// step multiple times without advancing the index.

self.count_since_last_iteration = 0;
self.last_picked_index = self.current_index;
self.last_picked_index = Some(self.current_index);
return Some(val);
}

Expand Down
7 changes: 7 additions & 0 deletions tests/histogram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<u64>::new(1).unwrap();
h += 0;
assert_eq!(h.iter_recorded().count(), 1);
}
Loading