#quantile #approximate #percentile #t-digest

tdigests

An efficient Rust implementation of the t-digest algorithm

4 releases (2 stable)

1.0.1 Dec 16, 2025
1.0.0 Jun 10, 2025
0.1.1 Oct 31, 2024
0.1.0 Oct 31, 2024

#210 in Cryptography

Download history 513/week @ 2025-10-24 590/week @ 2025-10-31 415/week @ 2025-11-07 626/week @ 2025-11-14 186/week @ 2025-11-21 509/week @ 2025-11-28 828/week @ 2025-12-05 935/week @ 2025-12-12 359/week @ 2025-12-19 820/week @ 2025-12-26 541/week @ 2026-01-02 654/week @ 2026-01-09 747/week @ 2026-01-16 1444/week @ 2026-01-23 897/week @ 2026-01-30 978/week @ 2026-02-06

4,198 downloads per month
Used in 2 crates

MIT license

30KB
517 lines

T-Digest Rust Library

Crates.io Docs.rs License

An efficient Rust implementation of the t-digest algorithm, which allows accurate estimation of quantiles and relative rank over streaming data.

Features

  • Quantile Estimation: Compute approximate quantiles (e.g., median, percentiles) from large datasets.
  • Streaming Data: Suitable for online computation where data arrives incrementally.
  • Merging Digests: Supports merging t-digests from different data partitions, ideal for distributed systems.
  • Compression: Adjustable compression factor to balance accuracy and memory usage.
  • Simple State: Minimal state structure for easy serialization and deserialization.

Installation

Add the following to your Cargo.toml:

[dependencies]
tdigests = 1.0

Usage

use tdigests::TDigest;

fn main() {
    // Create a new t-digest
    let digest = TDigest::from_values(vec![1.0, 2.0, 3.0]);

    // Estimate quantiles
    let median = digest.estimate_quantile(0.5);
    println!("Estimated median: {}", median);

    // Estimate rank
    let rank = digest.estimate_rank(2.5);
    println!("Rank of 2.5: {}", rank);
}

Examples

See the simple.rs for a complete example demonstrating how to use the t-digest library.

Contributing

Contributions are welcome! Please open issues or submit pull requests on the GitHub repository.

License

This project is licensed under the MIT License.

No runtime deps