Skip to content

KllSketch

Defined in: packages/distillate/src/kll/kll.ts:64

A KLL sketch: quantiles and ranks of a stream of numbers, each within a rank error of about 1.3% at the default k, in memory fixed by k.

const latency = KllSketch.create(0.01);
latency.add(12.5);

new KllSketch(params?): KllSketch

Defined in: packages/distillate/src/kll/kll.ts:84

Creates a sketch at an explicit k.

KllParams = {}

Accuracy and optional seed.

KllSketch

get count(): number

Defined in: packages/distillate/src/kll/kll.ts:290

Values recorded, weights included.

number


get isEmpty(): boolean

Defined in: packages/distillate/src/kll/kll.ts:295

Whether no value has been recorded.

boolean


get k(): number

Defined in: packages/distillate/src/kll/kll.ts:285

Items the top level holds.

number


get max(): number

Defined in: packages/distillate/src/kll/kll.ts:315

The largest value recorded, exactly; NaN while empty.

number


get min(): number

Defined in: packages/distillate/src/kll/kll.ts:310

The smallest value recorded, exactly; NaN while empty.

number


get numLevels(): number

Defined in: packages/distillate/src/kll/kll.ts:305

Levels of compaction, 1 until the first.

number


get retained(): number

Defined in: packages/distillate/src/kll/kll.ts:300

Items the sketch holds.

number

add(value, count?): void

Defined in: packages/distillate/src/kll/kll.ts:513

Records a value.

number

Any number but NaN; infinities and -0 are ordered as numbers.

number = 1

How many times to record it; a positive safe integer.

void

ParamError when value is NaN, count is not a positive safe integer, or the count would pass Number.MAX_SAFE_INTEGER. Nothing is recorded.


cdf(splits): number[]

Defined in: packages/distillate/src/kll/kll.ts:408

The cumulative distribution at splits: the fraction of the stream at or below each, then 1 for everything, each within the rank error.

readonly number[]

Strictly increasing numbers, none NaN.

number[]

splits.length + 1 fractions; all NaN while empty.

ParamError when splits are not strictly increasing or hold NaN.


equals(other): boolean

Defined in: packages/distillate/src/kll/kll.ts:260

Tests structural equality: true when other serializes to identical bytes, meaning the same k, generator state, counts and items.

KllSketch

The sketch to compare against.

boolean

true if the two sketches are byte-for-byte identical.


normalizedRankError(pmf?): number

Defined in: packages/distillate/src/kll/kll.ts:326

Rank error at 99% confidence, as a fraction of count.

boolean = false

true for the error over every rank of a CDF or PMF at once, false (the default) for a single rank or quantile.

number

The normalized rank error.


pmf(splits): number[]

Defined in: packages/distillate/src/kll/kll.ts:429

The mass between splits: the fraction of the stream at or below the first, then in each interval up to the next, then above the last.

readonly number[]

Strictly increasing numbers, none NaN.

number[]

splits.length + 1 fractions summing to 1; all NaN while empty.

ParamError as KllSketch.cdf does.


quantile(q): number

Defined in: packages/distillate/src/kll/kll.ts:339

The value at quantile q: the item at rank floor(q * (count - 1)) of the stream, within the rank error. q = 0 and q = 1 give min and max exactly.

number

The quantile, in [0, 1].

number

The estimate, or NaN when the sketch is empty.

ParamError when q is outside [0, 1].


quantiles(qs): number[]

Defined in: packages/distillate/src/kll/kll.ts:344

KllSketch.quantile for each of qs, in order.

readonly number[]

number[]


rank(x): number

Defined in: packages/distillate/src/kll/kll.ts:375

The fraction of the stream at or below x, within the rank error.

number

Any number but NaN.

number

The rank in [0, 1], or NaN when the sketch is empty.


toBytes(): Uint8Array

Defined in: packages/distillate/src/kll/kll.ts:223

Serializes the sketch, generator state included, to a portable little-endian byte layout.

Uint8Array

The serialized sketch, readable by KllSketch.fromBytes.


toJSON(): FilterJSON

Defined in: packages/distillate/src/kll/kll.ts:270

Serializes the sketch to a JSON-safe envelope wrapping KllSketch.toBytes.

FilterJSON

The envelope, readable by KllSketch.fromJSON.


union(other): KllSketch

Defined in: packages/distillate/src/kll/kll.ts:448

Merges two sketches into a new one that answers as a single sketch fed both streams would, within the rank error. Both are left untouched.

The result keeps the smaller k, as HyperLogLog keeps the coarser precision, so a coarse sketch merged with a fine one has the coarse one’s accuracy.

KllSketch

The sketch to merge with.

KllSketch

A new sketch of both streams, which takes values and further unions.

ParamError when the merged count would pass Number.MAX_SAFE_INTEGER.


static create(rankError): KllSketch

Defined in: packages/distillate/src/kll/kll.ts:104

Creates a sketch whose single-rank error meets rankError.

number

Target normalized rank error, e.g. 0.01 for 1%.

KllSketch

A new, empty sketch.


static fromBytes(bytes): KllSketch

Defined in: packages/distillate/src/kll/kll.ts:117

Restores a sketch from KllSketch.toBytes. It goes on taking values and flipping the coins the sketch that wrote it would have.

Uint8Array

The serialized sketch.

KllSketch

The reconstructed sketch.

SerializationError when the frame is malformed or not a KLL sketch.


static fromJSON(value): KllSketch

Defined in: packages/distillate/src/kll/kll.ts:280

Restores a sketch from its KllSketch.toJSON envelope.

unknown

The parsed envelope.

KllSketch

The reconstructed sketch.