Documentation
¶
Overview ¶
Package tdigest provides an approximate quantile estimator for streaming numeric data.
The implementation follows the t-digest algorithm by Ted Dunning (2013). A t-digest maintains a sorted list of centroids — (mean, weight) pairs — whose maximum size is bounded by the compression parameter δ. Centroids near the tails of the distribution are kept small (exact), while centroids near the median are allowed to be large (approximate). This trade-off gives good accuracy at the tails where precision matters most (P99, P999) and acceptable accuracy at the median.
Typical usage:
td := tdigest.New(100) // compression=100
for _, v := range values {
if err := td.Add(v); err != nil { ... }
}
p50, err := td.Quantile(0.5)
p99, err := td.Quantile(0.99)
td.Reset() // reuse without reallocating
This package is internal to xolu. It intentionally omits serialisation, merge, CDF, TrimmedMean, and other features not required by the timeseries subsystem.
Core algorithm and data structures adapted from github.com/caio/go-tdigest by Caio Alonso. For general-purpose use, use that library instead of this one.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TDigest ¶
type TDigest struct {
// contains filtered or unexported fields
}
TDigest is a streaming approximate quantile estimator. The zero value is not valid; use New.
func New ¶
New creates a TDigest with the given compression parameter δ. δ controls the maximum number of centroids: larger δ means more centroids, more memory, and better accuracy. Typical values: 50–200. δ must be > 0.
func (*TDigest) AddWeighted ¶
AddWeighted registers a sample that occurred count times. Returns an error if value is NaN or count is zero.