BSD style: see
license.txt
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(uint capacity) ¶#
-
Construct a cache with the specified maximum number of
entries. Additions to the cache beyond this number will
throw an exception
- ~this() ¶#
-
clean up when done
- void reaper(K, R)(K k, R r) [static] ¶#
-
Reaping callback for the hashmap, acting as a trampoline
- uint size() [final] ¶#
-
- 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(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.
- Ref deReference(Ref entry) [private] ¶#
-
Place a cache entry at the tail of the queue. This makes
it the least-recently referenced.
- Ref reReference(Ref entry) [private] ¶#
-
Move a cache entry to the head of the queue. This makes
it the most-recently referenced.
- Ref addEntry(K key, V value) [private] ¶#
-
Add an entry into the queue. An exception is thrown if
the queue is full
- struct QueuedEntry [private] ¶#
-
A doubly-linked list entry, used as a wrapper for queued
cache entries.
- Ref set(K key, V value) ¶#
-
Set this linked-list entry with the given arguments.
- Ref prepend(Ref before) ¶#
-
Insert this entry into the linked-list just in
front of the given entry.
- Ref append(Ref after) ¶#
-
Add this entry into the linked-list just after
the given entry.
- Ref extract() ¶#
-
Remove this entry from the linked-list. The
previous and next entries are patched together
appropriately.