new LruSet(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/lruset.js
Methods
-
add(item)
-
Adds an item, replacing either an existing equal item, or the oldest item when the maximum size would be exceeded; the added item becomes the newest. Returns the replaced item if it does not equal the inserted item, otherwise null.
If the maximum size is 0, do nothing and return the item.
Parameters:
Name Type Description item
Object the item to add.
- Source:
- mapspace/collections/lruset.js
Returns:
the replaced item.
- Type
- Object
-
clear()
-
Removes all items from the set.
- Source:
- mapspace/collections/lruset.js
-
each(fn)
-
Calls fn(item) for each item in the set, in an undefined order. Returns the number of times fn was called. The result is undefined if the set is mutated during iteration.
Parameters:
Name Type Description fn
function the function to call.
- Source:
- mapspace/collections/lruset.js
Returns:
Number of times fn was called.
- Type
- number
-
has(item)
-
Returns whether an item is in the set.
Parameters:
Name Type Description item
Object the key to search.
- Source:
- mapspace/collections/lruset.js
Returns:
True if item exists.
- Type
- boolean
-
modulus()
-
Gets the modulus.
- Source:
- mapspace/collections/lruset.js
Returns:
The modulus.
- Type
- number
-
remove(item)
-
Removes an item. Returns the removed item, or null if the item was not found.
Parameters:
Name Type Description item
Object the item to remove.
- Source:
- mapspace/collections/lruset.js
Returns:
the removed item.
- Type
- Object
-
size()
-
Returns the number of items in the set.
- Source:
- mapspace/collections/lruset.js
Returns:
Number of items.
- Type
- number