LRUMap
An implementation of a LRU (least recently used) map. This is a map that contains a maximum of k entries, where k is specified in the constructor. When the maximal number of entries is reached, it will evict the least recently used entry. This behaviour is useful for caches.
Constructor Summary
Public Constructor | ||
public |
constructor(maxSize: number) Instantiate a LRU map of maximum size maxSize. |
Member Summary
Public Members | ||
public get |
size: number The current size of the map. |
Method Summary
Public Methods | ||
public |
[Symbol.iterator](): Iterator<Array> Returns an iterator over key value pairs [k, v]. |
|
public |
clear(): * Clears the map. |
|
public |
delete(key: K): boolean Deletes a key from the map. |
|
public |
entries(): Iterator<Array> Returns an iterator over key value pairs [k, v]. |
|
public |
evict(k: number) Evicts the k least recently used entries from the map. |
|
public |
forEach(callback: function(key: K, value: V): *, thisArg: *): * Execute a given function for each key value pair in the map. |
|
public |
get(key: K): V Return the corresponding value to a specified key. |
|
public |
has(key: K): boolean Returns true if the specified key is to be found in the map. |
|
public |
keys(): Iterator<K> Returns an iterator over the keys of the map. |
|
public |
set(key: K, value: V) Inserts or replaces a key's value into the map. If the maxSize of the map is exceeded, the least recently used key is evicted first. Inserting a key implicitly accesses it. |
|
public |
values(): Iterator<V> Returns an iterator over the values of the map. |
Public Constructors
public constructor(maxSize: number) source
Instantiate a LRU map of maximum size maxSize.
Params:
Name | Type | Attribute | Description |
maxSize | number | The maximum size of the map. |
Public Members
Public Methods
public [Symbol.iterator](): Iterator<Array> source
Returns an iterator over key value pairs [k, v].
Return:
Iterator<Array> |
public delete(key: K): boolean source
Deletes a key from the map.
Params:
Name | Type | Attribute | Description |
key | K | The key to delete. |
Return:
boolean | Whether an entry was deleted. |
public entries(): Iterator<Array> source
Returns an iterator over key value pairs [k, v].
Return:
Iterator<Array> |
public evict(k: number) source
Evicts the k least recently used entries from the map.
Params:
Name | Type | Attribute | Description |
k | number |
|
The number of entries to evict (default is 1). |
public forEach(callback: function(key: K, value: V): *, thisArg: *): * source
Execute a given function for each key value pair in the map.
Params:
Name | Type | Attribute | Description |
callback | function(key: K, value: V): * | The function to be called. |
|
thisArg | * |
|
This value will be used as this when executing the function. |
Return:
* |
public get(key: K): V source
Return the corresponding value to a specified key.
Params:
Name | Type | Attribute | Description |
key | K | The key to look for. |
Return:
V | The value the key maps to (or undefined if not present). |
public has(key: K): boolean source
Returns true if the specified key is to be found in the map.
Params:
Name | Type | Attribute | Description |
key | K | The key to look for. |
Return:
boolean | True, if the key is in the map, false otherwise. |
public set(key: K, value: V) source
Inserts or replaces a key's value into the map. If the maxSize of the map is exceeded, the least recently used key is evicted first. Inserting a key implicitly accesses it.
Params:
Name | Type | Attribute | Description |
key | K | The key to set. |
|
value | V | The associated value. |
public values(): Iterator<V> source
Returns an iterator over the values of the map.
Return:
Iterator<V> |