pub struct DDSketch { /* private fields */ }Expand description
This is a minimal DDSketch implementation
This implementation only supports a part of the standard (which is also only the parts dd backend supports :shrug:)
- max length contiguous bin store, with lower bin collapse behavior.
- Positive or zero values
The default sketch has a 1% relative accuracy, and only accepts positive points
See https://github.com/DataDog/sketches-go for the reference implementation
Implementations§
Source§impl DDSketch
impl DDSketch
Sourcepub fn ordered_bins(&self) -> Vec<(f64, f64)>
pub fn ordered_bins(&self) -> Vec<(f64, f64)>
Return an iterator over (value, weight) pair for each bin
pub fn count(&self) -> f64
Sourcepub fn add(&mut self, point: f64) -> Result<(), Box<dyn Error>>
pub fn add(&mut self, point: f64) -> Result<(), Box<dyn Error>>
Add a point with value point to the sketch
point must be positive
Sourcepub fn add_with_count(
&mut self,
point: f64,
count: f64,
) -> Result<(), Box<dyn Error>>
pub fn add_with_count( &mut self, point: f64, count: f64, ) -> Result<(), Box<dyn Error>>
Add count point with value point to the sketch
count and point must be positive
Sourcepub fn with_log_mapping(gamma: f64, index_offset: f64) -> Option<Self>
pub fn with_log_mapping(gamma: f64, index_offset: f64) -> Option<Self>
A sketch whose logarithmic mapping has the given gamma and index_offset rather than
the default ones, or None if they do not describe a mapping.
Bins only line up between sketches whose mappings agree on both, so a producer whose consumer expects a particular mapping has to build its sketches with that mapping.
Sourcepub fn bin_index(&self, point: f64) -> Option<i32>
pub fn bin_index(&self, point: f64) -> Option<i32>
Index of the bin point falls into, or None for a point the sketch would count as
zero or does not accept.
Sourcepub fn add_to_bin(
&mut self,
index: i32,
count: f64,
) -> Result<(), Box<dyn Error>>
pub fn add_to_bin( &mut self, index: i32, count: f64, ) -> Result<(), Box<dyn Error>>
Add count points to the bin at index, as Self::bin_index numbers them.
For producers that bin values themselves and only hand the sketch their counts.
count must be positive, and index one that Self::bin_index can return.
Sourcepub fn encode_to_vec(self) -> Vec<u8> ⓘ
pub fn encode_to_vec(self) -> Vec<u8> ⓘ
Return a serialized protobuf of the sketch
Sourcepub fn from_pb(sketch: DdSketch) -> Option<DDSketch>
pub fn from_pb(sketch: DdSketch) -> Option<DDSketch>
Reconstruct a sketch from its protobuf. None if mapping missing/invalid.
Sourcepub fn from_encoded(bytes: &[u8]) -> Option<DDSketch>
pub fn from_encoded(bytes: &[u8]) -> Option<DDSketch>
Decode a sketch from serialized protobuf bytes; None on decode/mapping failure.