UNPKG

@barchart/common-js

Version:
91 lines (90 loc) 2.15 kB
/** * A map that is restricted to a certain capacity. If adding an * item would exceed the capacity; the oldest item is removed. * * @public */ export default class EvictingMap { /** * @param {number=} capacity - The maximum number of items the map can contain (defaults to ten). */ constructor(capacity?: number | undefined); /** * Returns true, if the map contains the item; otherwise false. * * @public * @param {string} key * @returns {boolean} */ public has(key: string): boolean; /** * Puts an item into the map (possibly causing eviction, if the size of the * list exceeds the capacity). * * @public * @param {string} key * @param {*} value */ public put(key: string, value: any): void; /** * Puts an item into the map (possibly causing eviction, if the size of the * list exceeds the capacity). * * @public * @param {string} key * @param {*} value */ public set(key: string, value: any): void; /** * Gets an item from the map, returning a null value if the no item * for the given key exists. * * @public * @param {string} key * @returns {*|null} */ public get(key: string): any | null; /** * Removes an item from the map. * * @public * @param {string} key */ public remove(key: string): void; /** * Removes an item from the map. * * @public * @param {string} key */ public delete(key: string): void; /** * Returns true, if the map contains no items; otherwise false. * * @public * @returns {boolean} */ public empty(): boolean; /** * Returns the number of items stored in the map. * * @public * @returns {number} */ public getSize(): number; /** * The capacity of the map. * * @public * @returns {number} */ public getCapacity(): number; /** * Returns a string representation. * * @public * @returns {string} */ public toString(): string; #private; }