Struct tdigest_ch::TDigest
source · pub struct TDigest { /* private fields */ }
Expand description
T-digest data structure for approximating the quantiles of a distribution.
§Examples
use tdigest_ch::TDigest;
let mut digest = TDigest::new();
// Add some elements.
digest.insert(1.0);
digest.insert(2.0);
digest.insert(3.0);
// Get the median of the distribution.
let quantile = digest.quantile(0.5);
assert_eq!(quantile, 2.0);
Implementations§
source§impl TDigest
impl TDigest
sourcepub fn builder() -> TDigestBuilder
pub fn builder() -> TDigestBuilder
Creates a TDigestBuilder
to configure a TDigest
.
This is the same as TDigestBuilder::new()
.
sourcepub fn append(&mut self, other: &mut TDigest)
pub fn append(&mut self, other: &mut TDigest)
Moves all the elements of other
into self
, leaving other
empty.
§Examples
use tdigest_ch::TDigest;
let mut a = TDigest::from([-10.0, 1.0, 2.0, 2.0, 3.0]);
let mut b = TDigest::from([-20.0, 5.0, 43.0]);
a.append(&mut b);
assert_eq!(a.len(), 8);
assert!(b.is_empty());
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the t-digest.
§Examples
use tdigest_ch::TDigest;
let mut digest = TDigest::new();
assert_eq!(digest.len(), 0);
digest.insert(1.0);
assert_eq!(digest.len(), 1);
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if the t-digest contains no elements.
§Examples
use tdigest_ch::TDigest;
let mut digest = TDigest::new();
assert!(digest.is_empty());
digest.insert(1.0);
assert!(!digest.is_empty());
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the t-digest, removing all values.
§Examples
use tdigest_ch::TDigest;
let mut digest = TDigest::new();
digest.insert(1.0);
digest.clear();
assert!(digest.is_empty());
sourcepub fn quantile(&mut self, level: f64) -> f32
pub fn quantile(&mut self, level: f64) -> f32
Returns the estimated quantile of the t-digest.
This method expects self
to be mutable, since the t-digest may be
compressed. If you require an immutable, shared reference to compute
quantiles, consider using quantiles
instead.
§Examples
use tdigest_ch::TDigest;
let mut digest = TDigest::from([1.0, 2.0, 3.0, 4.0, 5.0]);
assert_eq!(digest.quantile(0.0), 1.0);
assert_eq!(digest.quantile(0.5), 3.0);
assert_eq!(digest.quantile(1.0), 5.0);
sourcepub fn quantiles(&mut self) -> Quantiles<'_>
pub fn quantiles(&mut self) -> Quantiles<'_>
Creates an immutable quantile estimator from the t-digest.
§Examples
use std::thread;
use tdigest_ch::TDigest;
let mut digest = TDigest::from([1.0, 2.0, 3.0, 4.0, 5.0]);
let quantiles = digest.quantiles();
thread::scope(|s| {
s.spawn(|| {
assert_eq!(quantiles.get(0.0), 1.0);
});
s.spawn(|| {
assert_eq!(quantiles.get(0.5), 3.0);
});
s.spawn(|| {
assert_eq!(quantiles.get(1.0), 5.0);
});
});
sourcepub fn insert(&mut self, value: f32)
pub fn insert(&mut self, value: f32)
Adds a value to the t-digest.
§Examples
use tdigest_ch::TDigest;
let mut digest = TDigest::new();
digest.insert(1.0);
digest.insert(2.0);
assert_eq!(digest.len(), 2);
sourcepub fn insert_many(&mut self, value: f32, count: usize)
pub fn insert_many(&mut self, value: f32, count: usize)
Adds multiple values to the t-digest.
§Examples
use tdigest_ch::TDigest;
let mut digest = TDigest::new();
digest.insert_many(1.0, 1);
digest.insert_many(2.0, 2);
assert_eq!(digest.len(), 3);
Trait Implementations§
source§impl BitOr<&TDigest> for &TDigest
impl BitOr<&TDigest> for &TDigest
source§impl BitOrAssign<&TDigest> for TDigest
impl BitOrAssign<&TDigest> for TDigest
source§fn bitor_assign(&mut self, rhs: &TDigest)
fn bitor_assign(&mut self, rhs: &TDigest)
Merges self
and rhs
into self
.
§Examples
use tdigest_ch::TDigest;
let mut a = TDigest::from([1.0, 2.0, 3.0]);
let b = TDigest::from([3.0, 4.0, 5.0]);
a |= &b;
assert_eq!(a.len(), 6);
assert_eq!(a.quantile(0.5), 3.0);
source§impl<'de> Deserialize<'de> for TDigest
impl<'de> Deserialize<'de> for TDigest
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Extend<f32> for TDigest
impl Extend<f32> for TDigest
source§fn extend<I: IntoIterator<Item = f32>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = f32>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one
)Extends a collection with exactly one element.
source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
source§impl FromIterator<f32> for TDigest
impl FromIterator<f32> for TDigest
source§impl PartialEq for TDigest
impl PartialEq for TDigest
impl StructuralPartialEq for TDigest
Auto Trait Implementations§
impl Freeze for TDigest
impl RefUnwindSafe for TDigest
impl Send for TDigest
impl Sync for TDigest
impl Unpin for TDigest
impl UnwindSafe for TDigest
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more