UNPKG

@drift-labs/common

Version:

Common functions for Drift

20 lines (19 loc) 833 B
import { CircularBuffer } from './CircularBuffer'; /** * A circular buffer that only allows unique elements based on a key generator function. * When adding an element, if its generated key already exists in the buffer, the element * is not added and the add operation returns false. When the buffer is full and a new * unique element is added, the oldest element is removed to make space. */ export declare class UniqueCircularBuffer<T> extends CircularBuffer<T> { private uniquenessKeyGenerator; private uniqueKeys; constructor(capacity: number, uniquenessKeyGenerator: (value: T) => string); /** * Try add an element to the buffer. Returns true if the element was added, false if it was already in the buffer. * @param value * @returns */ add(value: T): boolean; toArray(): T[]; }