4 releases

0.1.4 Jan 3, 2026
0.1.3 Dec 11, 2025
0.1.2 Dec 7, 2025
0.1.1 Sep 21, 2025

#364 in Data structures

Download history 87/week @ 2025-11-09 119/week @ 2025-11-16 144/week @ 2025-11-23 413/week @ 2025-11-30 352/week @ 2025-12-07 415/week @ 2025-12-14 290/week @ 2025-12-21 190/week @ 2025-12-28 383/week @ 2026-01-04 235/week @ 2026-01-11 137/week @ 2026-01-18 48/week @ 2026-01-25 318/week @ 2026-02-01 416/week @ 2026-02-08

924 downloads per month

Apache-2.0 OR MIT

560KB
3K SLoC

Crates.io MIT / Apache 2.0 licensed Build Status

DDSketchy Logo

ddsketchy

📖 Docs

This is a Rust implementation of the DDSketch quantile sketch algorithm. DDSketch is a fully-mergeable quantile sketch with relative-error guarantees.

ddsketchy Features

  • Implements the DDSketch algorithm with configurable relative error guarantees
  • Optimized for high-throughput data collection scenarios
  • Designed for distributed systems with efficient sketch merging

Usage

use ddsketchy::{DDSketch, DDSketchError};

fn main() -> Result<(), DDSketchError> {
    // Create a new sketch with 1% relative error
    let mut sketch = DDSketch::new(0.01)?;

    // Add some values
    sketch.add(1.0);
    sketch.add(2.0);
    sketch.add(3.0);
    sketch.add(4.0);
    sketch.add(5.0);

    // Get the 50th percentile (median)
    let median = sketch.quantile(0.5)?;
    println!("Median: {}", median);

    // Get the 90th percentile
    let p90 = sketch.quantile(0.9)?;
    println!("90th percentile: {}", p90);

    Ok(())
}

Serialization Support

ddsketchy supports optional serialization via serde. Serialization is disabled by default to keep the library dependency-free. To enable it, add the serde feature

use ddsketchy::DDSketch;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut sketch = DDSketch::new(0.01)?;
    sketch.add(1.0);
    sketch.add(2.0);

    // Serialize to JSON
    let json = serde_json::to_string(&sketch)?;
    println!("Serialized: {}", json);

    // Deserialize from JSON
    let restored: DDSketch = serde_json::from_str(&json)?;

    // Verify the sketch works correctly
    assert_eq!(sketch.count(), restored.count());
    assert_eq!(sketch.quantile(0.5)?, restored.quantile(0.5)?);

    Ok(())
}

The serialization handles all internal state including infinity values for min/max bounds in empty sketches. Empty sketches serialize min/max as null values, while sketches with data serialize them as numbers.

References

Other implementations

Dependencies