Crates.io | tdigest |
lib.rs | tdigest |
version | 0.2.3 |
source | src |
created_at | 2019-08-15 05:04:35.236259 |
updated_at | 2021-11-11 22:19:27.496223 |
description | T-Digest algorithm in Rust |
homepage | |
repository | https://github.com/MnO2/t-digest |
max_upload_size | |
id | 156955 |
size | 35,656 |
This implementation is following Facebook folly's implementation
Add this to your Cargo.toml
:
[dependencies]
tdigest = "0.2"
then you are good to go. If you are using Rust 2015 you have to extern crate tdigest
to your crate root as well.
use tdigest::TDigest;
let t = TDigest::new_with_size(100);
let values: Vec<f64> = (1..=1_000_000).map(f64::from).collect();
let t = t.merge_sorted(values);
let ans = t.estimate_quantile(0.99);
let expected: f64 = 990_000.0;
let percentage: f64 = (expected - ans).abs() / expected;
assert!(percentage < 0.01);