Use the given allocator for allocations.
Constructs a HashSet with an initial bucket count of bucketCount. bucketCount must be a power of two.
Constructs a HashSet with an initial bucket count of bucketCount. bucketCount must be a power of two.
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.
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
Inserts the given item into the set.
Forward range interface
Removes the given item from the set.
the element type
the allocator to use. Defaults to Mallocator.
the hash function to use on the elements
true if the container should support holding references to GC-allocated memory.
1 import std.algorithm : canFind; 2 import std.array : array; 3 import std.range : walkLength; 4 import std.uuid : randomUUID; 5 6 auto s = HashSet!string(16); 7 assert(s.remove("DoesNotExist") == false); 8 assert(!s.contains("nonsense")); 9 assert(s.put("test")); 10 assert(s.contains("test")); 11 assert(!s.put("test")); 12 assert(s.contains("test")); 13 assert(s.length == 1); 14 assert(!s.contains("nothere")); 15 s.put("a"); 16 s.put("b"); 17 s.put("c"); 18 s.put("d"); 19 string[] strings = s[].array; 20 assert(strings.canFind("a")); 21 assert(strings.canFind("b")); 22 assert(strings.canFind("c")); 23 assert(strings.canFind("d")); 24 assert(strings.canFind("test")); 25 assert(*("a" in s) == "a"); 26 assert(*("b" in s) == "b"); 27 assert(*("c" in s) == "c"); 28 assert(*("d" in s) == "d"); 29 assert(*("test" in s) == "test"); 30 assert(strings.length == 5); 31 assert(s.remove("test")); 32 assert(s.length == 4); 33 s.clear(); 34 assert(s.length == 0); 35 assert(s.empty); 36 s.put("abcde"); 37 assert(s.length == 1); 38 foreach (i; 0 .. 10_000) 39 { 40 s.put(randomUUID().toString); 41 } 42 assert(s.length == 10_001); 43 44 // Make sure that there's no range violation slicing an empty set 45 HashSet!int e; 46 foreach (i; e[]) 47 assert(i > 0); 48 49 enum MAGICAL_NUMBER = 600_000; 50 51 HashSet!int f; 52 foreach (i; 0 .. MAGICAL_NUMBER) 53 assert(f.insert(i)); 54 assert(f.length == f[].walkLength); 55 foreach (i; 0 .. MAGICAL_NUMBER) 56 assert(i in f); 57 foreach (i; 0 .. MAGICAL_NUMBER) 58 assert(f.remove(i)); 59 foreach (i; 0 .. MAGICAL_NUMBER) 60 assert(!f.remove(i)); 61 62 HashSet!int g; 63 foreach (i; 0 .. MAGICAL_NUMBER) 64 assert(g.insert(i)); 65 66 static struct AStruct 67 { 68 int a; 69 int b; 70 } 71 72 HashSet!(AStruct*, Mallocator, a => a.a) fred; 73 fred.insert(new AStruct(10, 10)); 74 auto h = new AStruct(10, 10); 75 assert(h in fred);
Hash Set.