Skip to main content

PositiveOnlyDDSketch

Struct PositiveOnlyDDSketch 

Source
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>

Source

pub fn new(mapping: M, positive_store: S) -> Self

Creates a new PositiveOnlyDDSketch with the given mapping and store.

Source

pub fn add(&mut self, value: f64)

Adds a single value to the sketch.

Negative values are treated as zero.

Source

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.

Source

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.

Source

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.

Source

pub fn is_empty(&self) -> bool

Returns true if the sketch is empty.

Source

pub fn count(&self) -> u64

Returns the total number of values added to the sketch.

Source

pub fn clear(&mut self)

Clears the sketch, removing all values.

Source

pub fn mapping(&self) -> &M

Returns a reference to the index mapping.

Source

pub fn positive_store(&self) -> &S

Returns a reference to the positive value store.

Source

pub fn zero_count(&self) -> u64

Returns the count of values mapped to zero.

Source

pub fn relative_accuracy(&self) -> f64

Returns the relative accuracy of this sketch.

Source

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
Source

pub fn to_proto(&self) -> ProtoDDSketch

Converts this PositiveOnlyDDSketch to a protobuf DDSketch message.

The resulting protobuf will have no negativeValues field set.

Trait Implementations§

Source§

impl<M: Clone + IndexMapping, S: Clone + Store> Clone for PositiveOnlyDDSketch<M, S>

Source§

fn clone(&self) -> PositiveOnlyDDSketch<M, S>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<M: Debug + IndexMapping, S: Debug + Store> Debug for PositiveOnlyDDSketch<M, S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<M: IndexMapping + Default, S: Store + Default> Default for PositiveOnlyDDSketch<M, S>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<M: IndexMapping + PartialEq, S: Store + PartialEq> PartialEq for PositiveOnlyDDSketch<M, S>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<M: IndexMapping + PartialEq, S: Store + PartialEq> Eq for PositiveOnlyDDSketch<M, S>

Auto Trait Implementations§

§

impl<M, S> Freeze for PositiveOnlyDDSketch<M, S>
where M: Freeze, S: Freeze,

§

impl<M, S> RefUnwindSafe for PositiveOnlyDDSketch<M, S>

§

impl<M, S> Send for PositiveOnlyDDSketch<M, S>

§

impl<M, S> Sync for PositiveOnlyDDSketch<M, S>

§

impl<M, S> Unpin for PositiveOnlyDDSketch<M, S>
where M: Unpin, S: Unpin,

§

impl<M, S> UnwindSafe for PositiveOnlyDDSketch<M, S>
where M: UnwindSafe, S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more