kumulant

DDSketchStat

class DDSketchStat(val relativeError: Double = StatDefaults.DD_SKETCH_RELATIVE_ERROR, val probabilities: DoubleArray = StatDefaults.quantileProbabilities(), val minIndexableValue: Double = StatDefaults.DD_SKETCH_MIN_INDEXABLE_VALUE, val maxIndexableValue: Double = StatDefaults.DD_SKETCH_MAX_INDEXABLE_VALUE, val concurrency: Concurrency = Concurrency.None) : SeriesStat<SketchResult> (source)

DDSketchStat: relative-error quantile sketch with logarithmic bins.

Targets relativeError for quantile values within the indexable range. Out-of-range magnitudes fold into edge bins and lose that guarantee. Supports negative values via mirrored bins and a zero bucket. At a fixed indexable range, tightening relativeError grows bin count roughly as 1/epsilon.

Use cases: quantile / percentile monitoring of any positive-skewed scalar (latencies, payload sizes). Reach for this over TDigestStat when relative-error guarantees are required.

Memory: bounded by the indexable range, at log([maxIndexableValue] / [minIndexableValue]) / log(1 + [relativeError]) bins; roughly 2400 bins at the defaults. Values outside the range fold into the edge bins and still count toward every rank, so the bound holds whatever the input. Narrow the range if you know your data's span and want fewer bins at a tighter relativeError.

Update: O(1) per observation; one log/bin-assignment + striped atomic add. A NaN weight is inert, as everywhere in the library. A NaN value is a real observation with no bin of its own, so it falls into the zero bucket; filter it upstream with !X.isNaN() when that is not wanted.

Concurrency: Independent additive bins preserve per-cell updates under concurrent modes. Concurrency.HighWrite uses striped adders on the JVM; Concurrency.None uses plain cells. Multi-bin reads are not atomic, and floating-point results depend on update order.

Constructors

DDSketchStat

constructor(relativeError: Double = StatDefaults.DD_SKETCH_RELATIVE_ERROR, probabilities: DoubleArray = StatDefaults.quantileProbabilities(), minIndexableValue: Double = StatDefaults.DD_SKETCH_MIN_INDEXABLE_VALUE, maxIndexableValue: Double = StatDefaults.DD_SKETCH_MAX_INDEXABLE_VALUE, concurrency: Concurrency = Concurrency.None)(source)

Properties

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.

maxIndexableValue

Largest magnitude given its own bin. Anything larger folds into the top bin, on the same terms as minIndexableValue.

minIndexableValue

Smallest magnitude given its own bin. Anything smaller (but non-zero) folds into the bottom bin, so it still counts toward the rank but stops driving bin allocation.

probabilities

Quantiles to evaluate at read time.

relativeError

Relative value error target within the indexable range.

Functions

create

open override fun create(concurrency: Concurrency? = null): DDSketchStat(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: SketchResult, 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()): SketchResult(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: SketchResult)(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.