Class: LruMap

bu. LruMap

Creates a new LRU map given an equality predicate, hash function and maximum size. An LRU map holds up to a maximum number of items, ordered by their age. When the addition of an item would cause the maximum size to be exceeded, the new item replaces the oldest item in the map. As a special case, an LRU map with maximum size 0 always rejects the insertion of an item.


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:
bu/collections/lrumap.js

Methods


clear()

Removes all items from the map.

Source:
bu/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:
bu/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:
bu/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:
bu/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:
bu/collections/lrumap.js
Returns:

True if value for key exists.

Type
boolean

modulus()

Gets the modulus.

Source:
bu/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:
bu/collections/lrumap.js
Returns:

Value associated with key.

Type
Object

size()

Returns the number of items in the map.

Source:
bu/collections/lrumap.js
Returns:

Number of items.

Type
number