### 6 releases

0.2.3 | Nov 11, 2021 |
---|---|

0.2.2 | Nov 16, 2019 |

0.2.1 | Aug 15, 2019 |

0.1.1 | Aug 15, 2019 |

#**446** in Algorithms

**2,940** downloads per month

Used in **2** crates

**Apache-2.0**

24KB

541 lines

# T-Digest algorithm in rust

This implementation is following Facebook folly's implementation

## Installation

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

to your crate root as well.`extern` `crate` tdigest

## Example

`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``)``;`

###
`lib.rs`

:

T-Digest algorithm in rust

## Installation

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

to your crate root as well.`extern` `crate` tdigest

## Example

`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``)``;`

#### Dependencies

~170–420KB