Add key/value to hash if key is not in table. value can be lazy/callable.
iterator by keys
iterator by key/value pairs
iterator by values
throw away all keys
fetch is safe(do not return pointer) and nogc (do not throw exception) variant of "in" but in exchange of the cost of returning value instead of pointer we return ok = true and value if key in map, ok = false otherwise
get with default value it infers @safe, @nogc from user data: do not return ptr and do not thow
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
import std.range; import std.algorithm; import std.experimental.logger; HashMap!(string, int) counter; string[] words = [ "hello", "this", "simple", "example", "should", "succeed", "or", "it", "should", "fail" ]; // count words, simplest and fastest way foreach (word; words) { counter[word] = counter.getOrAdd(word, 0) + 1; } assert(counter.capacity == 32*4/5 - counter.length); assert(!counter.fetch("world").ok); assert(counter["hello"] == 1); assert(counter["should"] == 2); assert(counter.length == words.length - 1); // clear counter counter.clear; assert(counter.length == 0); // more verbose way to count foreach (word; words) { auto w = word in counter; if (w) { (*w)++; } else { counter[word] = 1; } } assert(!counter.fetch("world").ok); assert(counter["hello"] == 1); assert(counter["should"] == 2); assert(counter.length == words.length - 1); // iterators assert(counter.byKey.count == counter.byValue.count); assert(words.all!(w => w in counter)); // all words are in table assert(counter.byValue.sum == words.length); // sum of counters must equals to number of words