ddsketch/
lib.rs

1//! DDSketch implementations for quantile estimation.
2//!
3//! This crate provides two DDSketch implementations:
4//!
5//! - [`agent`]: Optimized for the Datadog Agent, with fixed compile-time configuration.
6//!   Use this when you need wire compatibility with the Datadog Agent or maximum
7//!   insertion performance.
8//!
9//! - [`canonical`]: Full implementation mirroring the official `sketches-go` library.
10//!   Use this when you need runtime-configurable accuracy or different store types.
11//!
12//! # Quick Start
13//!
14//! For most use cases, the agent implementation (re-exported at the crate root) is
15//! sufficient:
16//!
17//! ```
18//! use ddsketch::DDSketch;
19//!
20//! let mut sketch = DDSketch::default();
21//! sketch.insert(1.0);
22//! sketch.insert(2.0);
23//! sketch.insert(3.0);
24//!
25//! let median = sketch.quantile(0.5);
26//! ```
27//!
28//! For the canonical implementation with configurable accuracy:
29//!
30//! ```
31//! use ddsketch::canonical::DDSketch;
32//!
33//! let mut sketch = DDSketch::with_relative_accuracy(0.01).unwrap();
34//! sketch.add(1.0);
35//! sketch.add(2.0);
36//! sketch.add(3.0);
37//!
38//! let median = sketch.quantile(0.5);
39//! ```
40//!
41//! # Feature Flags
42//!
43//! - `serde`: Enables serialization/deserialization for the agent implementation.
44//!   **Warning**: The serialization format is not guaranteed to be stable.
45
46#![deny(warnings)]
47#![deny(missing_docs)]
48
49pub mod agent;
50pub mod canonical;
51
52mod common;
53
54// Re-export the agent implementation at the crate root for backward compatibility.
55// This allows `ddsketch::DDSketch` to work the same as the old `ddsketch_agent::DDSketch`.
56pub use agent::{Bin, Bucket, DDSketch};