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

histogram: skip empty buckets while downsampling #80

Merged
merged 1 commit into from
Oct 18, 2023
Merged
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
11 changes: 7 additions & 4 deletions histogram/src/standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ impl Histogram {
/// reduction factor should be 0 < factor < existing grouping power.
///
/// The specified factor determines how much the grouping power is reduced
/// by, with every step of grouping power approximately halvomh the total
/// number of buckets (and hence total size of thie histogram), while
/// by, with every step of grouping power approximately halves the total
/// number of buckets (and hence total size of the histogram), while
/// doubling the relative error.
///
/// This works by iterating over every bucket in the existing histogram
Expand All @@ -152,8 +152,11 @@ impl Histogram {

let mut histogram = Histogram::new(grouping_power - factor, self.config.max_value_power())?;
for (i, n) in self.as_slice().iter().enumerate() {
let val = self.config.index_to_lower_bound(i);
histogram.add(val, *n)?;
// Skip empty buckets
if *n != 0 {
let val = self.config.index_to_lower_bound(i);
histogram.add(val, *n)?;
}
}

Ok(histogram)
Expand Down