HashMap

Hash table implementation of a Map

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

bool get (K key, ref V element)
bool keyOf (V value, ref K key)
bool contains (V element)
bool containsPair (K key, V element)

bool removeKey (K key)
bool take (ref V element)
bool take (K key, ref V element)
size_t remove (V element, bool all)
size_t remove (IContainer!(V) e, bool all)
size_t replace (V oldElement, V newElement, bool all)
bool replacePair (K key, V oldElement, V newElement)

bool add (K key, V element)
bool opIndexAssign (V element, K key)
V    opIndex (K key)
V*   opIn_r (K key)

size_t size ()
bool isEmpty ()
V[] toArray (V[] dst)
HashMap dup ()
HashMap clear ()
HashMap reset ()
size_t buckets ()
float threshold ()
void buckets (size_t cap)
void threshold (float desired)

Constructors

this
this(float f)

Construct a HashMap instance

Destructor

~this
~this()

Clean up when deleted

Members

Functions

add
bool add(K key, V element)

Add a new element to the set. Does not add if there is an equivalent already present. Returns true where an element is added, false where it already exists (and was possibly updated).

add
bool add(K key, V element, K function(K) retain)

Add a new element to the set. Does not add if there is an equivalent already present. Returns true where an element is added, false where it already exists (and was possibly updated). This variation invokes the given retain function when the key does not already exist. You would typically use that to duplicate a char[], or whatever is required.

buckets
size_t buckets()

Return the number of buckets

buckets
HashMap buckets(size_t cap)

Set the desired number of buckets in the hash table. Any value greater than or equal to one is OK.

buckets
HashMap buckets(size_t cap, float threshold)

Set the number of buckets for the given threshold and resize as required

cache
HashMap cache(size_t chunk, size_t count)

Configure the assigned allocator with the size of each allocation block (number of nodes allocated at one time) and the number of nodes to pre-populate the cache with.

check
HashMap check()

Sanity check

clear
HashMap clear()

Clears the HashMap contents. Various attributes are retained, such as the internal table itself. Invoke reset() to drop everything.

contains
bool contains(V element)

Does this set contain the given element?

containsKey
bool containsKey(K key)

Time complexity: O(1) average; O(n) worst.

containsPair
bool containsPair(K key, V element)

Time complexity: O(1) average; O(n) worst.

get
bool get(K key, V element)

Return the element associated with key

isEmpty
bool isEmpty()

Is this container empty?

iterator
Iterator iterator()

Return a generic iterator for contained elements

keyOf
bool keyOf(V value, K key)

Time complexity: O(n).

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

Return the element associated with key

opIndex
V opIndex(K key)

Operator retreival function

opIndexAssign
bool opIndexAssign(V element, K key)

Operator shortcut for assignment

remove
size_t remove(IContainer!(V) e, bool all)

Remove a set of values

remove
size_t remove(V element, bool all)

Removes element instances, and returns the number of elements removed

removeKey
bool removeKey(K key)

Time complexity: O(1) average; O(n) worst.

replace
size_t replace(V oldElement, V newElement, bool all)

Replace instances of oldElement with newElement, and returns the number of replacements

replaceKey
bool replaceKey(K key, K replace)

Time complexity: O(1) average; O(n) worst.

replacePair
bool replacePair(K key, V oldElement, V newElement)

Time complexity: O(1) average; O(n) worst.

reset
HashMap reset()

Reset the HashMap contents. This releases more memory than clear() does

take
bool take(V element)

Remove and expose the first element. Returns false when no more elements are contained

take
bool take(K key, V value)

Remove and expose the element associated with key

threshold
float threshold()

Return the current load factor threshold

threshold
void threshold(float desired)

Set the resize threshold, and resize as required Set the current desired load factor. Any value greater than 0 is OK. The current load is checked against it, possibly causing a resize.

toArray
V[] toArray(V[] dst)

Copy and return the contained set of values in an array, using the optional dst as a recipient (which is resized as necessary).

Properties

dup
HashMap dup [@property getter]

Make an independent copy of the container. Does not clone elements

size
size_t size [@property getter]

Return the number of elements contained

Meta