pub struct TDigest { /* private fields */ }Expand description
Streaming quantile estimator with tight-tail accuracy.
TDigest is the streaming analogue of a percentile sketch —
record(x) is O(1) amortised, quantile(q) is O(δ), and
the maximum centroid count is ~2 · δ.
Implementations§
Source§impl TDigest
impl TDigest
Sourcepub fn new(compression: f64) -> RcfResult<Self>
pub fn new(compression: f64) -> RcfResult<Self>
Build a fresh digest with caller-chosen compression δ.
§Errors
Returns RcfError::InvalidConfig when compression is
non-finite or out of [2, 10_000].
Sourcepub fn with_default_compression() -> Self
pub fn with_default_compression() -> Self
Convenience: default compression (DEFAULT_COMPRESSION =
100).
Sourcepub fn compression(&self) -> f64
pub fn compression(&self) -> f64
Compression parameter δ.
Sourcepub fn total_weight(&self) -> f64
pub fn total_weight(&self) -> f64
Total weight across every record call (including pending
buffer entries).
Sourcepub fn centroid_count(&self) -> usize
pub fn centroid_count(&self) -> usize
Number of centroids — bounded by ~2·compression after a
flush.
Sourcepub fn min(&self) -> Option<f64>
pub fn min(&self) -> Option<f64>
Observed running minimum. None when no values have been
recorded yet.
Sourcepub fn max(&self) -> Option<f64>
pub fn max(&self) -> Option<f64>
Observed running maximum. None when no values have been
recorded yet.
Sourcepub fn record(&mut self, value: f64)
pub fn record(&mut self, value: f64)
Fold a single observation into the digest. Non-finite
values are silently ignored — the digest has no way to
surface an error per-call and silently dropping matches
crate::ScoreHistogram::record semantics.
Sourcepub fn flush(&mut self)
pub fn flush(&mut self)
Force-flush the pending buffer. Callers normally don’t need
this — Self::quantile flushes transparently — but it
helps bound memory in high-churn scenarios where quantiles
are queried rarely.
Sourcepub fn quantile(&mut self, q: f64) -> Option<f64>
pub fn quantile(&mut self, q: f64) -> Option<f64>
Quantile q in [0, 1]. Returns None when the digest is
empty; returns min at q = 0 and max at q = 1.
Sourcepub fn percentile(&mut self, p: f64) -> Option<f64>
pub fn percentile(&mut self, p: f64) -> Option<f64>
Percentile — shorthand for quantile(p / 100.0).
Sourcepub fn merge(&mut self, other: &Self) -> RcfResult<()>
pub fn merge(&mut self, other: &Self) -> RcfResult<()>
Merge other into self. Both digests must share the same
compression parameter; the merge preserves distributional
accuracy by re-running the scale-function compression pass.
§Errors
Returns RcfError::InvalidConfig when other.compression
does not match self.compression.
Trait Implementations§
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>,
Auto Trait Implementations§
impl Freeze for TDigest
impl RefUnwindSafe for TDigest
impl Send for TDigest
impl Sync for TDigest
impl Unpin for TDigest
impl UnsafeUnpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more