Skip to content

Commit

Permalink
Fix DDSketch::length() to count also the negative store
Browse files Browse the repository at this point in the history
  • Loading branch information
loyd committed Apr 10, 2024
1 parent d6069cb commit 1f7c3ae
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 1f7c3ae

Please sign in to comment.