kumulant

TDigestStat

class TDigestStat(val compression: Double = StatDefaults.TDIGEST_COMPRESSION, val probabilities: DoubleArray = StatDefaults.quantileProbabilities(), val concurrency: Concurrency = Concurrency.None) : SeriesStat<TDigestResult> (source)

Buffered merging T-Digest (Dunning) with k1 scaling function for high-fidelity extreme-quantile estimates and bounded centroid count. compression (delta) caps centroids to roughly ~6*delta.

Updates buffer values until the internal bufferCap is reached, then fold them into the sorted centroid list under the k1-difference ≤ 1 merge rule.

Use cases: approximate percentile estimation with adaptive resolution; tighter near the tails (0.001 / 0.999 percentiles), looser in the middle. Reach for this over DDSketchStat when you want extreme-quantile accuracy without committing to a relative-error parameter.

Memory: O(compression) centroids (~6 · delta) plus a fixed-size buffer.

Update: O(1) amortised per observation, with a periodic O(compression · log compression) compress when the buffer fills.

Concurrency: Body locked under any concurrent level. One lock protects buffer appends, compression, reads, merges, and resets, so observations cannot cross a buffer drain before their value and weight are stored. Concurrency.None runs without synchronisation. Centroid compression remains approximate and depends on update order.

Constructors

TDigestStat

constructor(compression: Double = StatDefaults.TDIGEST_COMPRESSION, probabilities: DoubleArray = StatDefaults.quantileProbabilities(), concurrency: Concurrency = Concurrency.None)(source)

Properties

compression

Compression parameter; higher permits more centroids and finer quantile resolution.

concurrency

open override val concurrency: Concurrency(source)

Thread-safety mode fixed at construction. See Concurrency for the shared contract and the implementation's KDoc for its cell and lock strategy.

probabilities

Quantiles to evaluate at read time.

Functions

create

open override fun create(concurrency: Concurrency? = null): TDigestStat(source)

Create an independent accumulator at the configured baseline. A null concurrency preserves this accumulator's mode; a non-null value overrides it. Modality subtypes narrow the return type to preserve the input shape.

merge

open override fun merge(values: TDigestResult, timestampNanos: Long = currentTimeNanos())(source)

Fold a compatible snapshot values into this accumulator at timestampNanos. Implementations document whether the combine is exact or approximate and which state the snapshot omits. The source accumulator is unaffected.

Time-dependent statistics, such as windows, place the snapshot at timestampNanos, which must share the clock the caller uses for updates and reads. Time-independent statistics ignore it.

read

open override fun read(timestampNanos: Long = currentTimeNanos()): TDigestResult(source)

Return the current result evaluated at timestampNanos. Time-independent statistics ignore the timestamp. Reading does not add an observation.

Snapshot consistency depends on the implementation's synchronisation. Locks protect coupled state under Concurrency.Strict and Concurrency.HighWrite; independently updated cells and JVM striped adders can still yield a best-effort snapshot. Concurrency.Relaxed permits drift across coupled cells.

reset

open override fun reset()(source)

Restore the configured baseline, including any prior seed. Preserves the configuration and concurrency.

validateMerge

open override fun validateMerge(values: TDigestResult)(source)

Validate values for merge without changing accumulator state. Containers validate every child before merging any of them. Successful validation checks compatibility; it does not make a concurrent merge transactional.

Link copied to clipboard
open fun update(value: Double, weight: Double = 1.0)

Record value with weight at the current monotonic time.

open override fun update(value: Double, timestampNanos: Long, weight: Double = 1.0)

Record value with weight at timestampNanos.

update

open override fun update(value: Double, timestampNanos: Long, weight: Double = 1.0)(source)

Record value with weight at timestampNanos.