Use the given allocator for allocations.
Constructs an HashMap with an initial bucket count of bucketCount. bucketCount must be a power of two.
Constructs an HashMap with an initial bucket count of bucketCount. bucketCount must be a power of two.
Gets the value for the given key, or returns defaultValue if the given key is not present.
Support for foreach(key, value; aa) { ... } syntax;
Supports key in aa syntax.
Supports aakey syntax.
Supports aakey = value; syntax.
Removes the value associated with the given key
the key type
the value type
the allocator type to use. Defaults to Mallocator
the hash function to use on the keys
true if the container should support holding references to GC-allocated memory.
import std.uuid : randomUUID; auto hm = HashMap!(string, int)(16); assert (hm.length == 0); assert (!hm.remove("abc")); hm["answer"] = 42; assert (hm.length == 1); assert ("answer" in hm); hm.remove("answer"); assert (hm.length == 0); hm["one"] = 1; hm["one"] = 1; assert (hm.length == 1); assert (hm["one"] == 1); foreach (i; 0 .. 1000) { hm[randomUUID().toString] = i; } assert (hm.length == 1001); assert (hm.keys().length == hm.length); assert (hm.values().length == hm.length); foreach (ref string k, ref int v; hm) {} auto hm2 = HashMap!(char, char)(4); hm2['a'] = 'a'; HashMap!(int, int) hm3; assert (hm3.get(100, 20) == 20); hm3[100] = 1; assert (hm3.get(100, 20) == 1);
Associative array / hash map.