Initial release: April 2008
Kris
0.99.7
- class StackMap(K, V, alias Hash = Container.hash, alias Reap = Container.reap, alias Heap = Container.Collect) ¶
-
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.
- 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
- ~this() ¶
-
- void reaper(K, R)(K k, R r) [static] ¶
-
Reaping callback for the hashmap, acting as a trampoline
- size_t size() [@property, final, const] ¶
-
- void clear() [final] ¶
-
- bool push(K key, V value) [final] ¶
-
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.
Returns true if we added a new entry; false if we just
replaced an existing one. A replacement does not change
the order of the keys, and thus does not change stack
ordering.
- bool popHead(ref K key, ref V value) ¶
-
Remove and return the more recent addition to the stack
- bool popTail(ref K key, ref V value) ¶
-
Remove and return the oldest addition to the stack
- int opApply(scope int delegate(ref K key, ref V value) dg) [final] ¶
-
Iterate from the oldest to the most recent additions
- bool add(K key, V value) [final] ¶
-
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.
Returns true if we added a new entry; false if we just
replaced an existing one. A replacement does not change
the order of the keys, and thus does not change stack
ordering.
- bool get(K key, ref V value) ¶
-
Get the cache entry identified by the given key
- bool take(K key, ref V value) [final] ¶
-
Remove (and return) the cache entry associated with the
provided key. Returns false if there is no such entry.