protocol SetAlgebraType| Inheritance |
ArrayLiteralConvertible, Equatable
View Protocol Hierarchy →
|
|---|---|
| Associated Types | |
| Import | import Swift |
Initializers
Creates the set containing all elements of sequence.
Declaration
init<S : SequenceType where S.Generator.Element == Element>(_ sequence: S)
Create an instance initialized with elements.
Declaration
init(arrayLiteral elements: Self.Element...)
Declared In
ArrayLiteralConvertible
Instance Variables
Returns true iff self.contains(e) is false for all e.
Declaration
var isEmpty: Bool { get }
Static Methods
Returns true iff a is disjoint with b.
Two elements are disjoint when neither one subsumes the other.
See Also: Self.element(, subsumes:_)
Declaration
static func element(a: Self.Element, isDisjointWith b: Self.Element) -> Bool
Returns true iff a subsumes b.
- Equivalent to
([a] as Self).isSupersetOf([b])
Declaration
static func element(a: Self.Element, subsumes b: Self.Element) -> Bool
Instance Methods
Returns true if lhs is equal to rhs.
Equality implies substitutability. When x == y, x and
y are interchangeable in any code that only depends on their
values.
Class instance identity as distinguished by triple-equals ===
is notably not part of an instance's value. Exposing other
non-value aspects of Equatable types is discouraged, and any
that are exposed should be explicitly pointed out in
documentation.
Equality is an equivalence relation
x == xistruex == yimpliesy == xx == yandy == zimpliesx == z
Inequality is the inverse of equality, i.e. !(x == y) iff
x != y.
Declaration
func ==(lhs: Self, rhs: Self) -> Bool
Declared In
Equatable
Returns true if self contains member.
- Equivalent to
self.intersect([member]) == [member]
Declaration
func contains(member: Self.Element) -> Bool
Returns the set of elements contained in self or in other,
but not in both self and other.
Declaration
func exclusiveOr(other: Self) -> Self
Replaces self with a set containing all elements contained in
either self or other, but not both.
- Equivalent to replacing
selfwithself.exclusiveOr(other)
Declaration
mutating func exclusiveOrInPlace(other: Self)
If member is not already contained in self, inserts it.
- Equivalent to
self.unionInPlace([member])Postcondition:self.contains(member)
Declaration
mutating func insert(member: Self.Element)
Returns the set of elements contained in both self and other.
Declaration
func intersect(other: Self) -> Self
Removes all elements of self that are not also present in
other.
- Equivalent to replacing
selfwithself.intersect(other)Postcondition:self.isSubsetOf(other)
Declaration
mutating func intersectInPlace(other: Self)
Returns true iff self.intersect(other).isEmpty.
Declaration
func isDisjointWith(other: Self) -> Bool
Returns true iff every element of self is contained in other.
Declaration
func isSubsetOf(other: Self) -> Bool
Returns true iff every element of other is contained in self.
Declaration
func isSupersetOf(other: Self) -> Bool
If member is contained in self, removes and returns it.
Otherwise, removes all elements subsumed by member and returns
nil.
Postcondition: self.intersect([member]).isEmpty
Declaration
mutating func remove(member: Self.Element) -> Self.Element?
Returns the set of elements contained in self but not in other.
Declaration
func subtract(other: Self) -> Self
Removes all elements of other from self.
- Equivalent to replacing
selfwithself.subtract(other).
Declaration
mutating func subtractInPlace(other: Self)
Returns the set of elements contained in self, in other, or in
both self and other.
Declaration
func union(other: Self) -> Self
Insert all elements of other into self.
- Equivalent to replacing
selfwithself.union(other). Postcondition:self.isSupersetOf(other)
Declaration
mutating func unionInPlace(other: Self)
Default Implementations
Creates the set containing all elements of sequence.
Declaration
init<S : SequenceType where S.Generator.Element == Element>(_ sequence: S)
Creates a set containing all elements of the given arrayLiteral.
This initializer allows an array literal containing
Self.Element to represent an instance of the set, wherever it
is implied by the type context.
Declaration
init(arrayLiteral: Self.Element...)
Returns true iff self.contains(e) is false for all e.
Declaration
var isEmpty: Bool { get }
Returns true iff a is disjoint with b.
Two elements are disjoint when neither one subsumes the other.
See Also: Self.element(, subsumes:_)
Declaration
static func element(a: Self.Element, isDisjointWith b: Self.Element) -> Bool
Returns true iff a subsumes b.
- Equivalent to
([a] as Self).isSupersetOf([b])
Declaration
static func element(a: Self.Element, subsumes b: Self.Element) -> Bool
Returns true iff self.intersect(other).isEmpty.
Declaration
func isDisjointWith(other: Self) -> Bool
Returns true iff every element of self is contained in other
and other contains an element that is not contained in self.
Declaration
func isStrictSubsetOf(other: Self) -> Bool
Returns true iff every element of other is contained in self
and self contains an element that is not contained in other.
Declaration
func isStrictSupersetOf(other: Self) -> Bool
Returns true iff every element of self is contained in other.
Declaration
func isSubsetOf(other: Self) -> Bool
Returns true iff every element of other is contained in self.
Declaration
func isSupersetOf(other: Self) -> Bool
Returns the set of elements contained in self but not in other.
Declaration
func subtract(other: Self) -> Self
Removes all elements of other from self.
- Equivalent to replacing
selfwithself.subtract(other).
Declaration
mutating func subtractInPlace(other: Self)
A generalized set whose distinct elements are not necessarily disjoint.
In a model of
SetAlgebraType, some elements may subsume other elements, whereIn many models of
SetAlgebraTypesuch asSet<Element>,asubsumesbif and only ifa == b, but that is not always the case. For example, option sets typically do not satisfy that property.Two elements are disjoint when neither one subsumes the other.
See Also:
OptionSetType.Axioms, where
Sconforms toSetAlgebraType,xandyare of typeS, andeis of typeS.Element:S() == []x.intersect(x) == xx.intersect([]) == []x.union(x) == xx.union([]) == xx.contains(e)impliesx.union(y).contains(e)x.union(y).contains(e)impliesx.contains(e) || y.contains(e)x.contains(e) && y.contains(e)iffx.intersect(y).contains(e)x.isSubsetOf(y)iffy.isSupersetOf(x)x.isStrictSupersetOf(y)iffx.isSupersetOf(y) && x != yx.isStrictSubsetOf(y)iffx.isSubsetOf(y) && x != y