pub struct PositiveOnlyDDSketch<M: IndexMapping = LogarithmicMapping, S: Store = CollapsingLowestDenseStore> { /* private fields */ }Expand description
A DDSketch optimized for positive-only values (e.g., latencies, durations).
This is a memory-optimized variant of DDSketch that eliminates the negative value store,
saving 48 bytes per sketch instance. Use this when you know all values will be non-negative,
such as when tracking latencies or other timing metrics.
Negative values are treated as zero (mapped to zero_count).
§Example
use ddsketch::canonical::PositiveOnlyDDSketch;
use ddsketch::canonical::mapping::FixedLogarithmicMapping;
use ddsketch::canonical::store::CollapsingLowestDenseStore;
let mut sketch: PositiveOnlyDDSketch<FixedLogarithmicMapping, CollapsingLowestDenseStore> =
PositiveOnlyDDSketch::default();
sketch.add(1.0);
sketch.add(2.0);
sketch.add(3.0);
let median = sketch.quantile(0.5).unwrap();Implementations§
Source§impl<M: IndexMapping, S: Store> PositiveOnlyDDSketch<M, S>
impl<M: IndexMapping, S: Store> PositiveOnlyDDSketch<M, S>
Sourcepub fn new(mapping: M, positive_store: S) -> Self
pub fn new(mapping: M, positive_store: S) -> Self
Creates a new PositiveOnlyDDSketch with the given mapping and store.
Sourcepub fn add(&mut self, value: f64)
pub fn add(&mut self, value: f64)
Adds a single value to the sketch.
Negative values are treated as zero.
Sourcepub fn add_n(&mut self, value: f64, n: u64)
pub fn add_n(&mut self, value: f64, n: u64)
Adds a value to the sketch with the given count.
Negative values are treated as zero.
Sourcepub fn quantile(&self, q: f64) -> Option<f64>
pub fn quantile(&self, q: f64) -> Option<f64>
Returns the approximate value at the given quantile.
The quantile must be in the range of [0, 1].
Returns None if the sketch is empty, or if the quantile is out of bounds.
Sourcepub fn merge(&mut self, other: &Self)where
M: PartialEq,
pub fn merge(&mut self, other: &Self)where
M: PartialEq,
Merges another sketch into this one.
The other sketch must use the same mapping type.
Sourcepub fn positive_store(&self) -> &S
pub fn positive_store(&self) -> &S
Returns a reference to the positive value store.
Sourcepub fn zero_count(&self) -> u64
pub fn zero_count(&self) -> u64
Returns the count of values mapped to zero.
Sourcepub fn relative_accuracy(&self) -> f64
pub fn relative_accuracy(&self) -> f64
Returns the relative accuracy of this sketch.
Sourcepub fn from_proto(
proto: &ProtoDDSketch,
mapping: M,
) -> Result<Self, ProtoConversionError>where
S: Default,
pub fn from_proto(
proto: &ProtoDDSketch,
mapping: M,
) -> Result<Self, ProtoConversionError>where
S: Default,
Creates a PositiveOnlyDDSketch from a protobuf DDSketch message.
This validates that the protobuf’s index mapping is compatible with the mapping type M,
then populates the store with the positive bin data. Any negative values in the protobuf
are ignored.
§Errors
Returns an error if:
- The protobuf is missing a mapping
- The mapping parameters don’t match the provided mapping
- Any bin counts are negative or non-integer
- The zero count is negative or non-integer
Trait Implementations§
Source§impl<M: Clone + IndexMapping, S: Clone + Store> Clone for PositiveOnlyDDSketch<M, S>
impl<M: Clone + IndexMapping, S: Clone + Store> Clone for PositiveOnlyDDSketch<M, S>
Source§fn clone(&self) -> PositiveOnlyDDSketch<M, S>
fn clone(&self) -> PositiveOnlyDDSketch<M, S>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<M: Debug + IndexMapping, S: Debug + Store> Debug for PositiveOnlyDDSketch<M, S>
impl<M: Debug + IndexMapping, S: Debug + Store> Debug for PositiveOnlyDDSketch<M, S>
Source§impl<M: IndexMapping + Default, S: Store + Default> Default for PositiveOnlyDDSketch<M, S>
impl<M: IndexMapping + Default, S: Store + Default> Default for PositiveOnlyDDSketch<M, S>
Source§impl<M: IndexMapping + PartialEq, S: Store + PartialEq> PartialEq for PositiveOnlyDDSketch<M, S>
impl<M: IndexMapping + PartialEq, S: Store + PartialEq> PartialEq for PositiveOnlyDDSketch<M, S>
impl<M: IndexMapping + PartialEq, S: Store + PartialEq> Eq for PositiveOnlyDDSketch<M, S>
Auto Trait Implementations§
impl<M, S> Freeze for PositiveOnlyDDSketch<M, S>
impl<M, S> RefUnwindSafe for PositiveOnlyDDSketch<M, S>where
M: RefUnwindSafe,
S: RefUnwindSafe,
impl<M, S> Send for PositiveOnlyDDSketch<M, S>
impl<M, S> Sync for PositiveOnlyDDSketch<M, S>
impl<M, S> Unpin for PositiveOnlyDDSketch<M, S>
impl<M, S> UnwindSafe for PositiveOnlyDDSketch<M, S>where
M: UnwindSafe,
S: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request