StackMap

StackMap extends the basic hashmap type by adding a limit to the number of items contained at any given time. In addition, StackMap retains the order in which elements were added, and employs that during foreach() traversal. Additions to the map beyond the capacity will result in an exception being thrown.

You can push and pop things just like an typical stack, and/or traverse the entries in the order they were added, though with the additional capability of retrieving and/or removing by key.

Note also that a push/add operation will replace an existing entry with the same key, exposing a twist on the stack notion.

Constructors

this
this(size_t capacity)

Construct a cache with the specified maximum number of entries. Additions to the cache beyond this number will throw an exception

Destructor

~this
~this()

clean up when done

Members

Functions

add
bool add(K key, V value)

Place an entry into the cache and associate it with the provided key. Note that there can be only one entry for any particular key. If two entries are added with the same key, the second effectively overwrites the first.

clear
void clear()
get
bool get(K key, V value)

Get the cache entry identified by the given key

opApply
int opApply(int delegate(ref K key, ref V value) dg)

Iterate from the oldest to the most recent additions

popHead
bool popHead(K key, V value)

Remove and return the more recent addition to the stack

popTail
bool popTail(K key, V value)

Remove and return the oldest addition to the stack

push
bool push(K key, V value)

Place an entry into the cache and associate it with the provided key. Note that there can be only one entry for any particular key. If two entries are added with the same key, the second effectively overwrites the first.

take
bool take(K key, V value)

Remove (and return) the cache entry associated with the provided key. Returns false if there is no such entry.

Properties

size
size_t size [@property getter]

Static functions

reaper
void reaper(K k, R r)

Reaping callback for the hashmap, acting as a trampoline

Meta