Skip to content

HyperLogLog

Defined in: packages/distillate/src/hll/hll.ts:86

A HyperLogLog sketch: estimates how many distinct keys it has seen, in space fixed by p rather than by the cardinality.

const sketch = HyperLogLog.create(0.01);
sketch.add("alice");

new HyperLogLog(params): HyperLogLog

Defined in: packages/distillate/src/hll/hll.ts:102

Creates a sketch at an explicit precision.

HllParams

Precision and optional hash seed.

HyperLogLog

get p(): number

Defined in: packages/distillate/src/hll/hll.ts:297

Precision: the sketch holds 2 ** p registers.

number


get seed(): number

Defined in: packages/distillate/src/hll/hll.ts:302

Hash seed the sketch was built with.

number


get standardError(): number

Defined in: packages/distillate/src/hll/hll.ts:307

Analytic relative standard error, 1.04 / sqrt(2 ** p).

number

add(key): void

Defined in: packages/distillate/src/hll/hll.ts:317

Records a key. Adding a key already seen leaves the sketch unchanged, which is what lets it count distinct values without storing them.

BytesLike

The key to record.

void


count(): number

Defined in: packages/distillate/src/hll/hll.ts:452

Counts how many distinct keys have been added. Below a few thousand distinct keys the answer is exact; above that, and once the sketch has gone dense, it estimates within standardError.

number

The cardinality, a whole number; 0 for an empty sketch.


equals(other): boolean

Defined in: packages/distillate/src/hll/hll.ts:434

Whether two sketches hold the same registers at the same precision and seed. Which representation each is in does not enter into it.

HyperLogLog

The sketch to compare against.

boolean

true if the two would answer every query identically.


toBytes(): Uint8Array

Defined in: packages/distillate/src/hll/hll.ts:239

Serializes the sketch to a portable little-endian byte layout.

Uint8Array

The serialized sketch, readable by HyperLogLog.fromBytes.


toJSON(): FilterJSON

Defined in: packages/distillate/src/hll/hll.ts:282

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

FilterJSON

The envelope, readable by HyperLogLog.fromJSON.


union(other): HyperLogLog

Defined in: packages/distillate/src/hll/hll.ts:359

Merges two sketches, giving a sketch that counts the keys either has seen.

Both operands are left untouched.

HyperLogLog

The sketch to merge with; must share this one’s seed.

HyperLogLog

A new sketch holding both key sets.

ParamError if the seeds differ, since the two would have sent the same key to different registers and the merge would mean nothing.


static create(relativeError): HyperLogLog

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

Creates a sketch whose standard error meets relativeError.

number

Target relative error, e.g. 0.01 for 1%.

HyperLogLog

A new, empty sketch.


static from(keys, relativeError): HyperLogLog

Defined in: packages/distillate/src/hll/hll.ts:132

Creates a sketch counting keys, sized to meet relativeError. The ergonomic entry point when the key set is already in hand.

Needs no count of the keys first, unlike the filters: a sketch is sized by the error it targets, not by how many keys it will see.

Iterable<BytesLike>

The keys to record.

number

Target relative error, e.g. 0.01 for 1%.

HyperLogLog

A new sketch holding every key.


static fromBytes(bytes): HyperLogLog

Defined in: packages/distillate/src/hll/hll.ts:146

Restores a sketch from its HyperLogLog.toBytes serialization.

Uint8Array

The serialized sketch.

HyperLogLog

The reconstructed sketch.


static fromJSON(value): HyperLogLog

Defined in: packages/distillate/src/hll/hll.ts:292

Restores a sketch from its HyperLogLog.toJSON envelope.

unknown

The parsed envelope.

HyperLogLog

The reconstructed sketch.