ProtocolSwift5.9.0

    SetAlgebra

    A type that provides mathematical set operations.

    protocol SetAlgebra<Element> : Equatable, ExpressibleByArrayLiteral

    You use types that conform to the SetAlgebra protocol when you need efficient membership tests or mathematical set operations such as intersection, union, and subtraction. In the standard library, you can use the Set type with elements of any hashable type, or you can easily create bit masks with SetAlgebra conformance using the OptionSet protocol. See those types for more information.

    Conforming to the SetAlgebra Protocol

    When implementing a custom type that conforms to the SetAlgebra protocol, you must implement the required initializers and methods. For the inherited methods to work properly, conforming types must meet the following axioms. Assume that S is a custom type that conforms to the SetAlgebra protocol, x and y are instances of S, and e is of type S.Element—the type that the set holds.

    • S() == []

    • x.intersection(x) == x

    • x.intersection([]) == []

    • x.union(x) == x

    • x.union([]) == x

    • x.contains(e) implies x.union(y).contains(e)

    • x.union(y).contains(e) implies x.contains(e) || y.contains(e)

    • x.contains(e) && y.contains(e) if and only if x.intersection(y).contains(e)

    • x.isSubset(of: y) implies x.union(y) == y

    • x.isSuperset(of: y) implies x.union(y) == x

    • x.isSubset(of: y) if and only if y.isSuperset(of: x)

    • x.isStrictSuperset(of: y) if and only if x.isSuperset(of: y) && x != y

    • x.isStrictSubset(of: y) if and only if x.isSubset(of: y) && x != y

    Supertypes

    Requirements

    Citizens in Swift

    Members

    Subtypes

    Available in Cxx

    Members

    • init<C>(C)

      Creates a set containing the elements of a C++ container.

    Extension in AsyncAlgorithms

    Members