A destructor is present on this object, but not explicitly documented in the source.
A postblit is present on this object, but not explicitly documented in the source.
Add key/value to hash if key is not in table. value can be lazy/callable. Returns: true if key were added.
iterator by keys
iterator by key/value pairs
iterator by values
when capacity == 0 - next put for new key can trigger resize
throw away all keys
dump HashMap content to string (for debugging)
fetch is safe(do not return pointer) and nogc (do not throw exception) variant of "in" but retuns tuple("ok", "value"). You can check if result.ok == true. It this case you'll find value in "value"
get with default value it infers @safe, @nogc from user data: do not return ptr and do not thow Returns: value from hash, or defaultValue if key not found (see also getOrAdd). defaultValue can be callable.
get value from hash or add if key is not in table. defaultValue can be callable. Returns: ref to value (maybe added)
get current grow factor.
set grow factor (can be between 2, 4 or 8).
get numter of keys in table
key in table Returns: pointer to stored value (if key in table) or null
"in" is unsafe as it can point to arbitrary address after resize
mapk = v;
put pair (k,v) into hash. inherits @safe and @nogc properties from K and V It can resize table if table is overloaded or has too much deleted entries. Returns: Nullable with old value if value was updated, or empty Nullable if we just stored new value.
remomve key from hash. Returns: true if actually removed, false otherwise.
get current buckets number
Example
1 import std.range; 2 import std.algorithm; 3 import std.experimental.logger; 4 HashMap!(string, int) counter; 5 string[] words = [ 6 "hello", "this", "simple", "example", "should", "succeed", "or", "it", 7 "should", "fail" 8 ]; 9 // count words, simplest and fastest way 10 foreach (word; words) { 11 counter[word] = counter.getOrAdd(word, 0) + 1; 12 } 13 assert(!counter.fetch("world").ok); 14 assert(counter.fetch("hello").value == 1); 15 assert(counter["hello"] == 1); 16 assert(counter["should"] == 2); 17 assert(counter.contains("hello")); 18 assert(counter.length == words.length - 1); 19 // iterators 20 assert(counter.byKey.count == counter.byValue.count); 21 assert(words.all!(w => counter.contains(w))); // all words are in table 22 assert(counter.byValue.sum == words.length); // sum of counters must equals to number of words