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
1 import std.array : array; 2 import std.algorithm : canFind; 3 import std.uuid : randomUUID; 4 5 auto s = HashSet!string(16); 6 assert(!s.contains("nonsense")); 7 assert(s.put("test")); 8 assert(s.contains("test")); 9 assert(!s.put("test")); 10 assert(s.contains("test")); 11 assert(s.length == 1); 12 assert(!s.contains("nothere")); 13 s.put("a"); 14 s.put("b"); 15 s.put("c"); 16 s.put("d"); 17 string[] strings = s.range.array; 18 assert(strings.canFind("a")); 19 assert(strings.canFind("b")); 20 assert(strings.canFind("c")); 21 assert(strings.canFind("d")); 22 assert(strings.canFind("test")); 23 assert(*("a" in s) == "a"); 24 assert(*("b" in s) == "b"); 25 assert(*("c" in s) == "c"); 26 assert(*("d" in s) == "d"); 27 assert(*("test" in s) == "test"); 28 assert(strings.length == 5); 29 assert(s.remove("test")); 30 assert(s.length == 4); 31 s.clear(); 32 assert(s.length == 0); 33 assert(s.empty); 34 s.put("abcde"); 35 assert(s.length == 1); 36 foreach (i; 0 .. 10_000) 37 { 38 s.put(randomUUID().toString); 39 } 40 assert(s.length == 10_001); 41 42 // Make sure that there's no range violation slicing an empty set 43 HashSet!int e; 44 foreach (i; e[]) 45 assert(i > 0); 46 47 HashSet!int f; 48 foreach (i; 0 .. 100) 49 assert(f.insert(i)); 50 foreach (i; 0 .. 100) 51 assert(f.remove(i)); 52 foreach (i; 0 .. 100) 53 assert(!f.remove(i)); 54 55 HashSet!int g; 56 foreach (i; 0 .. 100) 57 assert(g.insert(i));
Hash Set.