/// import { Hasher } from './backends/hasher'; export interface MultiSetCounter { add(val: string): void; count(): number; merge(other: MultiSetCounter): MultiSetCounter; precision(): number; serialize(): Buffer; } export type Options = { /** * The name of the hasher implementation to use. */ hasherId?: string; /** * Number of hash bits used to determine register index. This should be * `log2(r)` where `r` is the number of registers. **/ precision?: number; /** * Whether to correct for 'systematic multiplicative bias' resulting from * hash collisions. See the `count()` method for details (enabled by default) */ collisionAdjustment?: boolean; /** * Whether to make adjustments when the observed cardinality is more or less than * expected. See the counter `count()` method for details. (enabled by default) */ boundAdjustments?: boolean; }; /** * Re-export `Hasher` interface to allow thirdparty backends. */ export { Hasher } from './backends/hasher'; /** * A basic implementation of the 'HyperLogLog' datastructure which is useful for * estimating the number of distinct elements in a multiset. */ export declare class HyperLogLog implements MultiSetCounter { protected hasher: Hasher; protected registers: Uint8Array; protected opts: Options; /** * @param hasher The hashing backend to use. Any instance implementing the `Hasher` trait may be used. * @param options */ constructor(options?: Options); /** * @returns The number of bits used for the register index (e.g. 8-bits = 256 registers) */ precision(): number; /** * @param val Inserts a value into this set for counting. Duplicate values will only be * counted once in the resulting estimate. */ add(val: string): void; /** * Estimates the cardinality of all elements added to this set. This implementation * performs various adjustments as recommended by the HyperLogLog wikipedia entry: * * * When the estimate is low relative to the number of configured registers, 'Linear * Counting' is used instead of the standard method of estimation. A corresponding * adjustment is made when the cardinality is high relative to the size of the hash space. * These upper & lower bound adjustments may be controlled using the `boundAdjustments` * option (enabled by default). * * An additional correction is performed to compensate for overestimates resulting from hash * collisions. This correction can be controlled by the `collisionAdjustment` option * (enabled by default) */ count(): number; /** * Creates a new counter by merging the state of this with another - useful for distributed scenarios. * @returns A new `HyperLogLog` counter instance whose cardinality estimate reflects the * combined sets of the merged counters. The new counter inherits the `options` * of this instance (lhs). */ merge(other: HyperLogLog): HyperLogLog; /** * @returns A `Buffer` containing the state of this counter. Useful for transmitting * to another host for merging. */ serialize(): Buffer; /** * @returns A newly instantiated counter which mirrors a previously serialized one. */ static deserialize(rawBuf: Buffer): HyperLogLog; } //# sourceMappingURL=index.d.ts.map