Class LRUCache<K, V>

Implements a Least Recently Used fixed-capacity cache which supports updating, removing, and accessing keys in O(1).

Template

V

Type Parameters

  • K = any

  • V = any

Hierarchy

Constructors

Properties

items: Map<K, V> = ...
maxSize: number

Accessors

Methods

  • Removes a key from the cache and returns true if the key existed or false otherwise.

    Returns

    true if the key existed and was removed

    Parameters

    • key: K

    Returns boolean

  • Returns an iterable of all the [key, value] pairs in the cache, in insertion order.

    Returns

    Returns IterableIterator<[K, V]>

  • Get the value associated with the specified key, or undefined it not found.

    Returns

    The associated value or undefined

    Parameters

    • key: K

    Returns V

  • Removes the value associated with the specified key from the cache and returns the removed value if the key existed.

    Returns

    The value if it was removed or undefined.

    Parameters

    • key: K

    Returns V

  • Adds a new element with a specified key and value to the cache. If an element with the same key already exists, the element will be updated.

    Returns

    Parameters

    • key: K
    • value: V

    Returns LRUCache<K, V>

Generated using TypeDoc