kumulant

CrossingStat

class CrossingStat(val level: Double, val concurrency: Concurrency = Concurrency.None) : SeriesStat<CrossingResult> (source)

Counts strict upward and downward crossings of a configured level.

The very first update establishes the baseline side and is not counted as a crossing. Subsequent updates increment CrossingResult.upCrossings when the value transitions from below to at-or-above level, and CrossingResult.downCrossings on the reverse.

Use cases: alarm/recovery counting, level-crossing diagnostics, frequency estimation of band-limited signals.

Memory: O(1); three cells plus a baseline flag.

Update: O(1).

Concurrency: Per-cell atomics with bounded drift (category 1). Concurrent updates may briefly observe the previous side as stale and either over- or under-count by a small amount; the counts themselves are monotonic.

Constructors

CrossingStat

constructor(level: Double, 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.

level

The level to compare against.

Functions

create

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