kumulant

AbstractStatGroup

sealed class AbstractStatGroup<S : Stat<*>> : GroupedStat(source)

Internal base shared by StatGroup, PairedStatGroup, and VectorStatGroup. Holds the spec list and provides the modality-agnostic read / merge / reset implementations.

Inheritors

Properties

concurrency

The group's effective level: the one it was built with when a caller supplied it, otherwise the weakest level any child uses.

The two agree on the schema path, since a schema group builds every child at the level it was handed. They can diverge only when a caller supplies stats it built itself, which is what the vararg Pair constructor is for, and there the weakest child is the honest answer.

Callers introspect this to decide whether reads need external synchronisation, so the weakest child has to govern: the group can promise nothing its least-protected member does not. One Concurrency.None child makes the whole group unsafe to share, and one Concurrency.Relaxed child means a read can drift even if every sibling is exact.

The declaration order of Concurrency happens to run weakest to strongest, so minOfOrNull picks that child directly. Concurrency.HighWrite sorting last is not a claim that it is the strongest guarantee; it is exactly as exact as Concurrency.Strict and falls back to it off the JVM, so a mixed Strict / HighWrite group correctly reports Strict.

Computed once: the children are fixed at construction, so there is no reason to walk them again on every access.

Functions

merge

override fun merge(values: GroupResult)(source)

Fold another accumulator's snapshot into this one. The unit of merge is the immutable Result; not a live Stat; which is what lets the merge cross a process boundary. Many workers track slices of the same stream, call read periodically, ship snapshots to a coordinator, and the coordinator merges them in.

Most stat families implement merge exactly (Chan-style parallel formulas for Welford, cell-wise additions for histograms, cell-wise max for HLL). SGD-based regressors merge approximately; they have no second-moment information for the principled combine. Each stat's KDoc documents its merge semantics.

read

override fun read(timestampNanos: Long = currentTimeNanos()): GroupResult(source)

Materialise the current state as an immutable Result. Reads never mutate, so the caller can read as often as it likes without affecting the stream.

Snapshot consistency depends on the configured Concurrency. Under Concurrency.Strict / Concurrency.HighWrite a read locks against writers so coupled cells stay consistent. Under Concurrency.Relaxed the cells race and the snapshot may drift by ULPs of the workload under heavy contention; the drift is bounded and the read never throws.

timestampNanos is the read timestamp. Stats that don't care about time silently drop it; stats that do (rates, decay families, recency, windowed wrappers) use it as the ordering signal.

reset

override fun reset()(source)

Reset the stat to its prior-seeded baseline. Equivalent to constructing a fresh stat with the same configuration, but in place; keeps the same Concurrency and any per-stat tunables.

Link copied to clipboard
abstract fun create(concurrency: Concurrency? = null): Stat<GroupResult>

Spawn a fresh accumulator with the same configuration. Optionally override the Concurrency; useful for materialising a wire spec at a different concurrency level than the source.