kumulant

BloomFilterStat

class BloomFilterStat(val bits: Int = 1 shl 16, val hashes: Int = 7, val hasher: LongHasher = SplitMix64, val concurrency: Concurrency = Concurrency.None) : DiscreteStat<BloomFilterResult> (source)

Bloom filter - probabilistic set-membership test with no false negatives. bits bits are split across hashes positions per insert, derived from the hasher (default SplitMix64) via the Kirsch-Mitzenmacher double-hashing scheme.

False-positive rate is approximately (1 - e^(-hashes * n / bits))^hashes where n is the number of distinct inserts. Memory is bits / 64 Longs; mergeable element-wise via bitwise OR when bits and hashes match.

bits must be a power of two and a multiple of 64.

Use cases: membership queries with bounded memory; feature flags, deduplication of seen keys, "have we seen this user before". Tolerates false positives but never false negatives.

Memory: O(bits / 64) Longs, plus a totalSeen counter.

Update: O(hashes) per observation; hashes independent atomic OR ops.

Concurrency: Atomic OR on a striped Long array. Lock-free and exact under every Concurrency level; bit sets are idempotent and commutative.

Constructors

Link copied to clipboard
constructor(bits: Int = 1 shl 16, hashes: Int = 7, hasher: LongHasher = SplitMix64, concurrency: Concurrency = Concurrency.None)

Properties

Link copied to clipboard
val bits: Int
Link copied to clipboard
open override val concurrency: Concurrency

The thread-safety contract this stat was constructed with. Each stat picks the cell-encoding and lock strategy that honours this contract for its mathematical structure:

Link copied to clipboard

Mixer seeding the double-hashing scheme; defaults to SplitMix64.

Link copied to clipboard
val hashes: Int

Functions

Link copied to clipboard
open override fun create(concurrency: Concurrency? = null): BloomFilterStat

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.

Link copied to clipboard
open override fun merge(values: BloomFilterResult)

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.

Link copied to clipboard
open override fun read(timestampNanos: Long = currentTimeNanos()): BloomFilterResult

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.

Link copied to clipboard
open override fun reset()

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
open fun update(value: Long, weight: Double = 1.0)

Record an observation with the given weight, stamped at the current time.

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

Record an observation at timestampNanos with the given weight. Time matters for rate-shaped discrete stats; for cardinality / sketch stats the stamp is dropped.

BloomFilterStat

constructor(bits: Int = 1 shl 16, hashes: Int = 7, hasher: LongHasher = SplitMix64, concurrency: Concurrency = Concurrency.None)(source)

bits

concurrency

open override val concurrency: Concurrency(source)

The thread-safety contract this stat was constructed with. Each stat picks the cell-encoding and lock strategy that honours this contract for its mathematical structure:

Picked at construction; immutable after.

create

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

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.

The returned stat is independent: its state starts at the configured baseline, not at the source's current state. Each modality subtype narrows the return type so chaining doesn't lose the modality.

hasher

Mixer seeding the double-hashing scheme; defaults to SplitMix64.

hashes

merge

open override fun merge(values: BloomFilterResult)(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

open override fun read(timestampNanos: Long = currentTimeNanos()): BloomFilterResult(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

open 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.

update

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

Record an observation at timestampNanos with the given weight. Time matters for rate-shaped discrete stats; for cardinality / sketch stats the stamp is dropped.