kumulant

BloomFilterStat

class BloomFilterStat(val bits: Int = StatDefaults.BLOOM_FILTER_BITS, val hashes: Int = StatDefaults.BLOOM_FILTER_HASHES, 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

BloomFilterStat

constructor(bits: Int = StatDefaults.BLOOM_FILTER_BITS, hashes: Int = StatDefaults.BLOOM_FILTER_HASHES, hasher: LongHasher = SplitMix64, concurrency: Concurrency = Concurrency.None)(source)

Properties

bits

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.

hasher

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

hashes

Functions

create

open override fun create(concurrency: Concurrency? = null): BloomFilterStat(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: BloomFilterResult, 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()): BloomFilterResult(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: BloomFilterResult)(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: Long, weight: Double = 1.0)

Record value with weight at the current monotonic time.

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

Record value with weight at timestampNanos.

update

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

Record value with weight at timestampNanos.