ddsketch/canonical/store/
mod.rs1use datadog_protos::sketches::Store as ProtoStore;
4
5use super::error::ProtoConversionError;
6
7mod collapsing_highest;
8pub use self::collapsing_highest::CollapsingHighestDenseStore;
9
10mod collapsing_lowest;
11pub use self::collapsing_lowest::CollapsingLowestDenseStore;
12
13mod dense;
14pub use self::dense::DenseStore;
15
16mod sparse;
17pub use self::sparse::SparseStore;
18
19pub trait Store: Clone + Send + Sync {
24 fn add(&mut self, index: i32, count: u64);
26
27 fn total_count(&self) -> u64;
29
30 fn min_index(&self) -> Option<i32>;
32
33 fn max_index(&self) -> Option<i32>;
35
36 fn key_at_rank(&self, rank: u64) -> Option<i32>;
40
41 fn merge(&mut self, other: &Self);
43
44 fn is_empty(&self) -> bool;
46
47 fn clear(&mut self);
49
50 fn merge_from_proto(&mut self, proto: &ProtoStore) -> Result<(), ProtoConversionError>;
52
53 fn to_proto(&self) -> ProtoStore;
55}
56
57pub(crate) fn validate_proto_count(index: i32, count: f64) -> Result<u64, ProtoConversionError> {
63 if count < 0.0 {
64 return Err(ProtoConversionError::NegativeBinCount { index, count });
65 }
66 if count.fract() != 0.0 {
67 return Err(ProtoConversionError::NonIntegerBinCount { index, count });
68 }
69 Ok(count as u64)
70}