Constructs a HashSet with an initial bucket count of bucketCount. bucketCount must be a power of two.
Forward range interface
Inserts the given item into the set.
Removes all items from the set
Inserts the given item into the set.
Supports a in b syntax
Forward range interface
Removes the given item from the set.
the element type
the hash function to use on the elements
import std.array : array; import std.algorithm : canFind; import std.uuid : randomUUID; auto s = HashSet!string(16); assert (!s.contains("nonsense")); s.put("test"); s.put("test"); assert (s.contains("test")); assert (s.length == 1); assert (!s.contains("nothere")); s.put("a"); s.put("b"); s.put("c"); s.put("d"); string[] strings = s.range.array; assert (strings.canFind("a")); assert (strings.canFind("b")); assert (strings.canFind("c")); assert (strings.canFind("d")); assert (strings.canFind("test")); assert (strings.length == 5); assert (s.remove("test")); assert (s.length == 4); s.clear(); assert (s.length == 0); assert (s.empty); s.put("abcde"); assert (s.length == 1); foreach (i; 0 .. 10_000) { s.put(randomUUID().toString); } assert (s.length == 10_001); // Make sure that there's no range violation slicing an empty set HashSet!int e; foreach (i; e[]) assert (i > 0);
Hash Set.