Set

Set structure

Members

Functions

add
void add(K k)

add element to set

create
void create(R range)

Fill set from range

difference
auto difference(Set!K other)

create difference of two sets

intersection
auto intersection(Set!K other)

create intersection of two sets

iterate
auto iterate()

iterate over items

join
void join(Set!K other)

join other set to this set

length
auto length()

number of items in set

opBinaryRight
bool opBinaryRight(K k)

if element present in set

remove
void remove(K k)

remove element from set

Examples

import std.stdio;

Set!string s;
s.add("hello");
assert(s.length == 1);
assert(equal(s.iterate, only("hello")));
s.remove("hello");
assert(s.length == 0);
s.remove("hello");
assert(s.length == 0);

s.create(only("hello", "hello", "world"));
assert(s.length == 2);

s.join(set(only("and", "bye")));
assert(s.length == 4);

auto other = set(only("and", "bye", "!"));
auto cross0 = s.intersection(other);
assert("bye" in cross0);
assert("!"  !in cross0);
auto cross1 = other.intersection(s);
assert(cross0.length == cross1.length);
assert("and" in cross0 && "and" in cross1);
assert("bye" in cross0 && "bye" in cross1);

auto nums = set(iota(10));
auto someNums = nums.difference(set(only(1,2,3)));
assert(0 in someNums);
assert(1 !in someNums);

bool f(const Set!string s) {
    return "yes" in s;
}

Set!string ss;
ss.add("yes");
f(ss);
assert("yes" in ss);

Meta