containers.immutablehashset
Immutable hash set.
License
-
Declaration
structImmutableHashSet(T, alias hashFunction);The immutable hash set is useful for constructing a read-only collection that supports quickly determining if an element is present.
Discussion
Because the set does not support inserting, it only takes up as much memory as is necessary to contain the elements provided at construction. Memory is managed my malloc/free.
Examples
auto ihs1 = immutable ImmutableHashSet!(int, a => a)([1, 3, 5, 19, 31, 40, 17]); assert (ihs1.contains(1)); assert (ihs1.contains(3)); assert (ihs1.contains(5)); assert (ihs1.contains(19)); assert (ihs1.contains(31)); assert (ihs1.contains(40)); assert (ihs1.contains(17)); assert (!ihs1.contains(100)); assert (ihs1[].length == 7); auto ihs2 = immutable ImmutableHashSet!(int, a => a)([]); assert (ihs2.length == 0); assert (ihs2.empty); assert (ihs2[].length == 0); assert (!ihs2.contains(42));
-
Declaration
this(); -
Declaration
immutable this(const T[]values);Constructs an immutable hash set from the given
values. Thevaluesmust not have any duplicates. -
Declaration
immutable @safe immutable(T)[]opSlice();Return Value
A GC-allocated array containing the contents of this set.
-
Declaration
immutable boolcontains(Tvalue);Return Value
trueif this setcontainsthe givenvalue. -
Declaration
immutable size_tlength;The number of items in the set.
-
Declaration
immutable boolempty;True if the set is
empty.