/** * A Least Recently Used (LRU) cache implementation * using a Map for O(1) get/set operations. * * When the cache exceeds its capacity, the least recently used * entry is evicted. * * ## Features * - **get(key)**: Retrieve a value (moves it to most recently used) * - **set(key, value)**: Insert or update a value * - **has(key)**: Check if a key exists * - **delete(key)**: Remove a specific entry * - **clear()**: Remove all entries * - **size**: Get the number of entries * * ## Time Complexity * - get: O(1) * - set: O(1) * - has: O(1) * - delete: O(1) * * @example * ```typescript * const cache = new LRUCache(3); * cache.set("a", 1); * cache.set("b", 2); * cache.set("c", 3); * * cache.get("a"); // 1 (moves "a" to most recently used) * cache.set("d", 4); // evicts "b" (least recently used) * * cache.has("b"); // false * cache.get("a"); // 1 * ``` * * @template K - The type of cache keys * @template V - The type of cache values */ export declare class LRUCache { private capacity; private map; /** * Creates a new LRUCache instance. * @param capacity - The maximum number of entries the cache can hold * * @example * ```typescript * const cache = new LRUCache(100); * ``` */ constructor(capacity: number); /** * Returns the number of entries in the cache. * @returns The current number of cached entries * * @example * ```typescript * const cache = new LRUCache(10); * cache.set("a", 1); * console.log(cache.size); // 1 * ``` */ get size(): number; /** * Retrieves a value by key and marks it as most recently used. * @param key - The key to look up * @returns The value if found, or undefined if not in cache * * @example * ```typescript * const cache = new LRUCache(10); * cache.set("a", 1); * cache.get("a"); // 1 * cache.get("b"); // undefined * ``` */ get(key: K): V | undefined; /** * Inserts or updates a key-value pair. * If the cache is at capacity, the least recently used entry is evicted. * @param key - The key to set * @param value - The value to associate with the key * * @example * ```typescript * const cache = new LRUCache(2); * cache.set("a", 1); * cache.set("b", 2); * cache.set("c", 3); // evicts "a" * ``` */ set(key: K, value: V): void; /** * Checks whether a key exists in the cache. * Does not affect the recently-used order. * @param key - The key to check * @returns True if the key exists in the cache * * @example * ```typescript * const cache = new LRUCache(10); * cache.set("a", 1); * cache.has("a"); // true * cache.has("b"); // false * ``` */ has(key: K): boolean; /** * Removes an entry from the cache by key. * @param key - The key to remove * @returns True if the entry was found and removed * * @example * ```typescript * const cache = new LRUCache(10); * cache.set("a", 1); * cache.delete("a"); // true * cache.delete("b"); // false * ``` */ delete(key: K): boolean; /** * Removes all entries from the cache. * * @example * ```typescript * const cache = new LRUCache(10); * cache.set("a", 1); * cache.set("b", 2); * cache.clear(); * console.log(cache.size); // 0 * ``` */ clear(): void; /** * Evicts the least recently used entry (first inserted). */ private evict; }