A destructor is present on this object, but not explicitly documented in the source.
iterator by keys
iterator by key/value pairs
iterator by values
throw away all keys
get
get value from hash or add if key is not in table. defaultValue can be callable.
get current grow factor.
set grow factor (can be between 2, 4 or 8).
get numter of keys in table
key in table
mapk = v;
put pair (k,v) into hash.
remomve key from hash.
get current buckets number
Example
1 import std.range; 2 import std.algorithm; 3 4 HashMap!(string, int) counter; 5 string[] words = ["hello", "this", "simple", "example", "should", "succeed", "or", "it", "should", "fail"]; 6 // count words, simplest and fastest way 7 foreach (word; words) 8 { 9 counter.getOrAdd(word, 0)++; 10 } 11 assert("world" !in counter); 12 assert(counter["hello"] == 1); 13 assert(counter["should"] == 2); 14 assert(counter.length == words.length - 1); 15 // clear counter 16 counter.clear; 17 assert(counter.length == 0); 18 // more verbose way to count 19 foreach (word; words) 20 { 21 auto w = word in counter; 22 if (w) 23 { 24 (*w)++; 25 } 26 else 27 { 28 counter[word] = 1; 29 } 30 } 31 assert("world" !in counter); 32 assert(counter["hello"] == 1); 33 assert(counter["should"] == 2); 34 assert(counter.length == words.length - 1); 35 // iterators 36 assert(counter.byKey.count == counter.byValue.count); 37 assert(words.all!(w => w in counter)); // all words are in table 38 assert(counter.byValue.sum == words.length); // sum of counters must equals to number of words