hash(into:)
Hashes the essential components of this value by feeding them into the given hasher.
func hash(into hasher: inout Hasher)
Parameters
- hasher
The hasher to use when combining the components of this instance.
Hashes the essential components of this value by feeding them into the given hasher.
func hash(into hasher: inout Hasher)
where Element:Hashable
The hasher to use when combining the components of this instance.
import Swift
@frozen struct Set<Element> where Element : Hashable
An unordered collection of unique elements.
@frozen struct Hasher
The universal hash function used by Set
and Dictionary
.
protocol Hashable : Equatable
A type that can be hashed into a Hasher
to produce an integer hash value.
init()
Creates an empty set.
init<Source>(_ sequence: Source) where Element == Source.Element, Source : Sequence
Creates a new set from a finite sequence of items.
init(arrayLiteral elements: Element...)
Creates a set containing the elements of the given array literal.
var capacity: Int { get }
The total number of elements that the set can contain without allocating new storage.
var count: Int { get }
The number of elements in the set.
var customMirror: Mirror { get }
A mirror that reflects the set.
var debugDescription: String { get }
A string that represents the contents of the set, suitable for debugging.
var description: String { get }
A string that represents the contents of the set.
var endIndex: Set<Element>.Index { get }
The “past the end” position for the set—that is, the position one greater than the last valid subscript argument.
var isEmpty: Bool { get }
A Boolean value that indicates whether the set is empty.
var startIndex: Set<Element>.Index { get }
The starting position for iterating members of the set.
subscript(position: Set<Element>.Index) -> Element { get }
Accesses the member at the given position.
static func == (lhs: Set<Element>, rhs: Set<Element>) -> Bool
Returns a Boolean value indicating whether two sets have equal elements.
func contains(_ member: Element) -> Bool
Returns a Boolean value that indicates whether the given element exists in the set.
func filter(_ isIncluded: (Element) throws -> Bool) rethrows -> Set<Element>
Returns a new set containing the elements of the set that satisfy the given predicate.
func firstIndex(of member: Element) -> Set<Element>.Index?
Returns the index of the given element in the set, or nil
if the element is not a member of the set.
func formIndex(after i: inout Set<Element>.Index)
mutating func formIntersection<S>(_ other: S) where Element == S.Element, S : Sequence
Removes the elements of the set that aren’t also in the given sequence.
mutating func formSymmetricDifference(_ other: Set<Element>)
Removes the elements of the set that are also in the given sequence and adds the members of the sequence that are not already in the set.
mutating func formSymmetricDifference<S>(_ other: S) where Element == S.Element, S : Sequence
Replace this set with the elements contained in this set or the given set, but not both.
mutating func formUnion<S>(_ other: S) where Element == S.Element, S : Sequence
Inserts the elements of the given sequence into the set.
func index(after i: Set<Element>.Index) -> Set<Element>.Index
@discardableResult mutating func insert(_ newMember: Element) -> (inserted: Bool, memberAfterInsert: Element)
Inserts the given element in the set if it is not already present.
func intersection(_ other: Set<Element>) -> Set<Element>
Returns a new set with the elements that are common to both this set and the given sequence.
func intersection<S>(_ other: S) -> Set<Element> where Element == S.Element, S : Sequence
Returns a new set with the elements that are common to both this set and the given sequence.
func isDisjoint(with other: Set<Element>) -> Bool
Returns a Boolean value that indicates whether this set has no members in common with the given set.
func isDisjoint<S>(with other: S) -> Bool where Element == S.Element, S : Sequence
Returns a Boolean value that indicates whether the set has no members in common with the given sequence.
func isStrictSubset(of other: Set<Element>) -> Bool
Returns a Boolean value that indicates whether the set is a strict subset of the given sequence.
func isStrictSubset<S>(of possibleStrictSuperset: S) -> Bool where Element == S.Element, S : Sequence
Returns a Boolean value that indicates whether the set is a strict subset of the given sequence.
func isStrictSuperset(of other: Set<Element>) -> Bool
Returns a Boolean value that indicates whether the set is a strict superset of the given sequence.
func isStrictSuperset<S>(of possibleStrictSubset: S) -> Bool where Element == S.Element, S : Sequence
Returns a Boolean value that indicates whether the set is a strict superset of the given sequence.
func isSubset(of other: Set<Element>) -> Bool
Returns a Boolean value that indicates whether this set is a subset of the given set.
func isSubset<S>(of possibleSuperset: S) -> Bool where Element == S.Element, S : Sequence
Returns a Boolean value that indicates whether the set is a subset of the given sequence.
func isSuperset(of other: Set<Element>) -> Bool
Returns a Boolean value that indicates whether this set is a superset of the given set.
func isSuperset<S>(of possibleSubset: S) -> Bool where Element == S.Element, S : Sequence
Returns a Boolean value that indicates whether the set is a superset of the given sequence.
func makeIterator() -> Set<Element>.Iterator
Returns an iterator over the members of the set.
mutating func popFirst() -> Element?
Removes and returns the first element of the set.
@discardableResult mutating func remove(_ member: Element) -> Element?
Removes the specified element from the set.
@discardableResult mutating func remove(at position: Set<Element>.Index) -> Element
Removes the element at the given index of the set.
mutating func removeAll(keepingCapacity keepCapacity: Bool = false)
Removes all members from the set.
@discardableResult mutating func removeFirst() -> Element
Removes the first element of the set.
mutating func reserveCapacity(_ minimumCapacity: Int)
Reserves enough space to store the specified number of elements.
mutating func subtract(_ other: Set<Element>)
Removes the elements of the given set from this set.
mutating func subtract<S>(_ other: S) where Element == S.Element, S : Sequence
Removes the elements of the given sequence from the set.
func subtracting(_ other: Set<Element>) -> Set<Element>
Returns a new set containing the elements of this set that do not occur in the given set.
func subtracting<S>(_ other: S) -> Set<Element> where Element == S.Element, S : Sequence
Returns a new set containing the elements of this set that do not occur in the given sequence.
func symmetricDifference<S>(_ other: S) -> Set<Element> where Element == S.Element, S : Sequence
Returns a new set with the elements that are either in this set or in the given sequence, but not in both.
func union<S>(_ other: S) -> Set<Element> where Element == S.Element, S : Sequence
Returns a new set with the elements of both this set and the given sequence.
@discardableResult mutating func update(with newMember: Element) -> Element?
Inserts the given element into the set unconditionally.
@frozen struct Index
The position of an element in a set.
@frozen struct Iterator
An iterator over the members of a Set<Element>
.