Skip to content

Latest commit

 

History

History
72 lines (49 loc) · 1.33 KB

File metadata and controls

72 lines (49 loc) · 1.33 KB

API: DDSketch

Status: Ready

Purpose

Approximate quantile estimation with relative error guarantees.

Type/Struct

  • DDSketch

Constructors

fn new(alpha: f64) -> Self

Insert/Update

fn add<T: NumericalValue>(&mut self, val: &T)
fn add_input(&mut self, v: &DataInput) -> Result<(), &'static str>

add accepts any type implementing NumericalValue (all standard integer and float primitives). Values are internally converted to f64; non-positive or non-finite values are ignored. add_input is the DataInput adapter used by the type-erased dispatch path.

Query

fn get_value_at_quantile(&self, q: f64) -> Option<f64>
fn get_count(&self) -> u64
fn min(&self) -> Option<f64>
fn max(&self) -> Option<f64>

Merge

fn merge(&mut self, other: &DDSketch)

Serialization

fn serialize_to_bytes(&self) -> Result<Vec<u8>, RmpEncodeError>
fn deserialize_from_bytes(bytes: &[u8]) -> Result<Self, RmpDecodeError>

Examples

use asap_sketchlib::DDSketch;

let mut dds = DDSketch::new(0.01);
dds.add(&1.0_f64);
dds.add(&2_i32);
let p50 = dds.get_value_at_quantile(0.5).unwrap();
assert!(p50 >= 1.0);

Caveats

  • Inputs must be positive values.
  • Merge requires compatible configuration (alpha).

Status

Supported and tested for multiple distributions.