Lyricdev
GitHub

class Set

pub class Set<T :: [Hashable], H :: [Hasher] = DefaultHasher> :: [Iterable, Contains<T>]

Conforms to Iterable, Contains<T>, FromArrayLiteral<T>, Equatable, Debug, Display, FromIterator<T>, Clone.

A hash set: values, each once, in no order of its own.

It is a Map's keys over the same table, so membership, insertion and removal take expected constant time. x in set is set.contains(x). The set operations — Set.union, Set.intersect, Set.difference, Set.symmetricDifference — are methods that return a new set. Not safe across threads.

Methods

pub static fn withHasher(seed: H): Set<T, H>

Creates an empty set whose values are hashed with seed.

pub fn length(): int

Returns how many values it holds.

pub fn isEmpty(): bool

Returns whether it holds no values.

pub fn contains(v: T): bool

Returns whether it holds v.

pub mut fn insert(v: T): bool

Adds v and returns whether it was not there before.

pub mut fn remove(v: T): bool

Removes v and returns whether it was there.

pub mut fn clear(): void

Removes every value.

pub fn iter(): MapKeysIter<T, bool, H>

Returns an iterator over the values, in no order of the set's own.

Panics

The next pull panics (LYR-RT0016) after a value is inserted or removed, or the set cleared, while the iterator walks.

pub static fn new(): Set<T, DefaultHasher>

Creates an empty set hashing with the process's key; its order differs from run to run.

pub static fn of(xs: T[]): Set<T, DefaultHasher>

Creates a set of the array's elements, each once.

pub static fn withCapacity(n: int): Set<T, DefaultHasher>

Creates an empty set with room for n values before it grows.

Panics

When n is negative.

pub fn union(other: Set<T, H>): Set<T, H>

Returns a new set of the values in either set, hashing as this one does.

pub fn intersect(other: Set<T, H>): Set<T, H>

Returns a new set of the values in both sets, hashing as this one does.

pub fn difference(other: Set<T, H>): Set<T, H>

Returns a new set of the values in this set but not in other, hashing as this one does.

pub fn symmetricDifference(other: Set<T, H>): Set<T, H>

Returns a new set of the values in exactly one of the two sets, hashing as this one does.

pub fn isSubset(other: Set<T, H>): bool

Returns whether every value of this set is in other.

The empty set is a subset of every set.

pub fn isSuperset(other: Set<T, H>): bool

Returns whether every value of other is in this set.

pub fn isDisjoint(other: Set<T, H>): bool

Returns whether the two sets have no value in common.

static fn fromLiteral(items: T[]): Set<T, DefaultHasher>
fn equals(o: Set<T, H>): bool
fn debug(): string
fn debugTo(out: StringBuilder): void
fn show(): string
fn showTo(out: StringBuilder): void
static fn fromIter<I :: [Iterator<Item = T>]>(it: I): Set<T, DefaultHasher> throws I.Error
fn clone(): Set<T, H>