Struct Set

The Set type supports set operations. Sets can be instantiated with an explicitly specified base type, in which case the range of values that the Set can contain is limited by the base type. Sets can also be constructed with an implicitly derived base type using the set() functions, where the underlying data is managed dynamically and the range of values that the set can contain is only limited by the available memory. Base types are ordinal types like the standard signed and unsigned integer types of various sizes, but also char types, booleans and custom enumerations.

struct Set(T) ;

Constructors

NameDescription
this

Fields

NameTypeDescription
bits BitArray
minval T

Methods

NameDescription
card Returns the cardinality of the set (the number of members). O(n).
init
opApply Support for foreach loops over members of the Set.
opBinary Support for set operations. "+": set union "-": set difference "*": set intersection "%": set symmetric difference (A + B - A * B)
opBinaryRight Support for set membership testing using in.
opOpAssign ditto (+= etc)
staticArray

Example

auto i1 = Interval!byte(10, 20);
auto i2 = Interval!byte(15);
byte a = 7;
auto s1 = Set!byte(i1, i2, Interval!byte(a));
assert(7 in s1);

Example

auto s1 = Set!byte(Interval!byte(10, 20));
assert(5 !in s1);
assert(20 in s1);

enum Count {One, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten}
auto i1 = Interval!Count(Count.Three, Count.Six);
auto i2 = Interval!Count(Count.Eight, Count.Ten);
auto s2 = Set!Count(i1, i2);
assert(s2.card == 7);
assert(Count.Nine in s2);
s2 -= Set!Count(i2);
assert(s2.card == 4);
assert(Count.Four in s2);
assert(Count.Nine !in s2);