transitory
Version:
In-memory cache with high hit rates via LFU eviction. Supports time-based expiration, automatic loading and metrics.
28 lines (27 loc) • 967 B
TypeScript
import { KeyType } from '../KeyType';
/**
* Count-min sketch suitable for use with W-TinyLFU. Similiar to a regular
* count-min sketch but with a few important differences to achieve better
* estimations:
*
* 1) Enforces that the width of the sketch is a power of 2.
* 2) Uses a reset that decays all values by half when width * 10 additions
* have been made.
*/
export declare class CountMinSketch {
private readonly width;
private readonly depth;
readonly maxSize: number;
readonly halfMaxSize: number;
readonly slightlyLessThanHalfMaxSize: number;
private additions;
readonly resetAfter: number;
private table;
constructor(width: number, depth: number, decay: boolean);
private findIndex;
update(hashCode: number): void;
estimate(hashCode: number): number;
private performReset;
static hash(key: KeyType): number;
static uint8(width: number, depth: number, decay?: boolean): CountMinSketch;
}