new LruMap(equals, hash, maxsize)
Parameters:
Name | Type | Description |
---|---|---|
equals |
function | the equality predicate. |
hash |
function | the hash function. |
maxsize |
number | the maximum size. |
- Source:
- mapspace/collections/lrumap.js
Methods
-
clear()
-
Removes all items from the map.
- Source:
- mapspace/collections/lrumap.js
-
del(key)
-
Removes the item associated with the specified key. Returns the removed value, or null if not found.
Parameters:
Name Type Description key
string the key to search.
- Source:
- mapspace/collections/lrumap.js
Returns:
The removed value.
- Type
- Object
-
each(fn)
-
Calls fn(key, value) for each item in the map, in an undefined order. Returns the number of times fn was called. The result is undefined if the map is mutated during iteration.
Parameters:
Name Type Description fn
function the function to call.
- Source:
- mapspace/collections/lrumap.js
Returns:
Number of times fn was called.
- Type
- number
-
get(key)
-
Returns the value associated to the specified key, or null if not found.
Parameters:
Name Type Description key
string the key to search.
- Source:
- mapspace/collections/lrumap.js
Returns:
Value associated with key.
- Type
- Object
-
has(key)
-
Returns whether there is a value associated with the specified key.
Parameters:
Name Type Description key
string the key to search.
- Source:
- mapspace/collections/lrumap.js
Returns:
True if value for key exists.
- Type
- boolean
-
modulus()
-
Gets the modulus.
- Source:
- mapspace/collections/lrumap.js
Returns:
The modulus.
- Type
- number
-
set(key)
-
Sets the specified key to the specified value, replacing either an existing item with the same key, or the oldest item when the maximum size would be exceeded; the added item becomes the newest. Returns the replaced key if it does not equal the inserted key, otherwise null.
If the maximum size is 0, do nothing and return the key.
Parameters:
Name Type Description key
string the key to search.
- Source:
- mapspace/collections/lrumap.js
Returns:
Value associated with key.
- Type
- Object
-
size()
-
Returns the number of items in the map.
- Source:
- mapspace/collections/lrumap.js
Returns:
Number of items.
- Type
- number