Skip to content

Commit

Permalink
Merge pull request #12 from loyd/master
Browse files Browse the repository at this point in the history
Fix `DDSketch::length()` to count also the negative store
  • Loading branch information
mheffner committed Jun 1, 2024
2 parents d6069cb + 1f7c3ae commit 9c4da2d
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/ddsketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl DDSketch {
/// Returns the length of the underlying `Store`. This is mainly only useful for understanding
/// how much the sketch has grown given the inserted values.
pub fn length(&self) -> usize {
self.store.length() as usize
self.store.length() as usize + self.negative_store.length() as usize
}

/// Merge the contents of another sketch into this one. The sketch that is merged into this one
Expand Down Expand Up @@ -352,4 +352,22 @@ mod tests {
assert!(dd.quantile(0.5).unwrap().is_some());
assert!(dd.quantile(0.75).unwrap().is_some());
}

#[test]
fn test_length() {
let mut dd = DDSketch::default();
assert_eq!(dd.length(), 0);

dd.add(1.0);
assert_eq!(dd.length(), 128);
dd.add(2.0);
dd.add(3.0);
assert_eq!(dd.length(), 128);

dd.add(-1.0);
assert_eq!(dd.length(), 256);
dd.add(-2.0);
dd.add(-3.0);
assert_eq!(dd.length(), 256);
}
}

0 comments on commit 9c4da2d

Please sign in to comment.