Set

struct Set<T : Hashable>

A collection of unique T instances with no defined ordering.

Inheritance ArrayLiteralConvertible, CollectionType, DebugPrintable, Equatable, Hashable, Printable, Reflectable, SequenceType, _CollectionType, _SequenceType, _Sequence_Type View Protocol Hierarchy →
Associated Types
Element = T
Index = SetIndex<T>
GeneratorType = SetGenerator<T>
Generator = SetGenerator<T>

Type alias inferred.

SubSequence = Slice<Set<T>>

Type alias inferred.

Import import Swift

Initializers

init()

Create an empty Set.

Declaration

init()
init(_:)

Create a Set from a finite sequence of items.

Declaration

init<S : SequenceType where T == T>(_ sequence: S)
init(arrayLiteral:)

Declaration

init(arrayLiteral elements: T...)
init(minimumCapacity:)

Create an empty set with at least the given number of elements worth of storage. The actual capacity will be the smallest power of 2 that's >= minimumCapacity.

Declaration

init(minimumCapacity: Int)

Instance Variables

var count: Int

The number of members in the set.

Complexity: O(1)

Declaration

var count: Int { get }
var debugDescription: String

A textual representation of self, suitable for debugging.

Declaration

var debugDescription: String { get }
var description: String

A textual representation of self.

Declaration

var description: String { get }
var endIndex: SetIndex<T>

The collection's "past the end" position.

endIndex is not a valid argument to subscript, and is always reachable from startIndex by zero or more applications of successor().

Complexity: amortized O(1) if self does not wrap a bridged NSSet, O(N) otherwise.

Declaration

var endIndex: SetIndex<T> { get }
var first: T?

The first element obtained when iterating, or nil if self is empty. Equivalent to self.generate().next()

Declaration

var first: T? { get }
var hashValue: Int

Declaration

var hashValue: Int { get }
var isEmpty: Bool

true if the set is empty.

Declaration

var isEmpty: Bool { get }
var startIndex: SetIndex<T>

The position of the first element in a non-empty set.

This is identical to endIndex in an empty set.

Complexity: amortized O(1) if self does not wrap a bridged NSSet, O(N) otherwise.

Declaration

var startIndex: SetIndex<T> { get }

Subscripts

subscript(_: SetIndex<T>)

Declaration

subscript(position: SetIndex<T>) -> T { get }

Instance Methods

func contains(_:)

Returns true if the set contains a member.

Declaration

func contains(member: T) -> Bool
func exclusiveOr(_:)

Return a new set with elements that are either in the set or a finite sequence but do not occur in both.

Declaration

func exclusiveOr<S : SequenceType where T == T>(sequence: S) -> Set<T>
mutating func exclusiveOrInPlace(_:)

For each element of a finite sequence, remove it from the set if it is a common element, otherwise add it to the set. Repeated elements of the sequence will be ignored.

Declaration

mutating func exclusiveOrInPlace<S : SequenceType where T == T>(sequence: S)
func generate()

Return a generator over the members.

Complexity: O(1)

Declaration

func generate() -> SetGenerator<T>
func getMirror()

Returns a mirror that reflects self.

Declaration

func getMirror() -> MirrorType
func indexOf(_:)

Returns the Index of a given member, or nil if the member is not present in the set.

Declaration

func indexOf(member: T) -> SetIndex<T>?
mutating func insert(_:)

Insert a member into the set.

Declaration

mutating func insert(member: T)
func intersect(_:)

Return a new set with elements common to this set and a finite sequence.

Declaration

func intersect<S : SequenceType where T == T>(sequence: S) -> Set<T>
mutating func intersectInPlace(_:)

Remove any members of this set that aren't also in a finite sequence.

Declaration

mutating func intersectInPlace<S : SequenceType where T == T>(sequence: S)
func isDisjointWith(_:)

Returns true if no members in the set are in a finite sequence as a Set.

Declaration

func isDisjointWith<S : SequenceType where T == T>(sequence: S) -> Bool
func isStrictSubsetOf(_:)

Returns true if the set is a subset of a finite sequence as a Set but not equal.

Declaration

func isStrictSubsetOf<S : SequenceType where T == T>(sequence: S) -> Bool
func isStrictSupersetOf(_:)

Returns true if the set is a superset of a finite sequence as a Set but not equal.

Declaration

func isStrictSupersetOf<S : SequenceType where T == T>(sequence: S) -> Bool
func isSubsetOf(_:)

Returns true if the set is a subset of a finite sequence as a Set.

Declaration

func isSubsetOf<S : SequenceType where T == T>(sequence: S) -> Bool
func isSupersetOf(_:)

Returns true if the set is a superset of a finite sequence as a Set.

Declaration

func isSupersetOf<S : SequenceType where T == T>(sequence: S) -> Bool
mutating func remove(_:)

Remove the member from the set and return it if it was present.

Declaration

mutating func remove(member: T) -> T?
mutating func removeAll(_:)

Erase all the elements. If keepCapacity is true, capacity will not decrease.

Declaration

mutating func removeAll(keepCapacity: Bool = default)
mutating func removeAtIndex(_:)

Remove the member referenced by the given index.

Declaration

mutating func removeAtIndex(index: SetIndex<T>)
mutating func removeFirst()

Remove a member from the set and return it. Requires: count > 0.

Declaration

mutating func removeFirst() -> T
func subtract(_:)

Return a new set with elements in this set that do not occur in a finite sequence.

Declaration

func subtract<S : SequenceType where T == T>(sequence: S) -> Set<T>
mutating func subtractInPlace(_:)

Remove all members in the set that occur in a finite sequence.

Declaration

mutating func subtractInPlace<S : SequenceType where T == T>(sequence: S)
func union(_:)

Return a new Set with items in both this set and a finite sequence.

Declaration

func union<S : SequenceType where T == T>(sequence: S) -> Set<T>
mutating func unionInPlace(_:)

Insert elements of a finite sequence into this Set.

Declaration

mutating func unionInPlace<S : SequenceType where T == T>(sequence: S)