# SortedSet

``public struct SortedSet<Element: Comparable>: SetAlgebra``

A sorted collection of unique comparable elements. `SortedSet` is like `Set` in the standard library, but it always keeps its elements in ascending order. Lookup, insertion and removal of any element has logarithmic complexity.

`SortedSet` is a struct with copy-on-write value semantics, like Swift’s standard collection types. It uses an in-memory b-tree for element storage, whose individual nodes may be shared with other sorted sets. Mutating a set whose storage is (partially or completely) shared requires copying of only O(log(`count`)) elements. (Thus, mutation of shared `SortedSet`s may be cheaper than ordinary `Set`s, which need to copy all elements.)

Set operations on sorted sets (such as taking the union, intersection or difference) can take as little as O(log(n)) time if the elements in the input sets aren’t too interleaved.

`SortedBag`
• ``` init() ```

Create an empty set.

#### Declaration

Swift

``public init()``
• ``` init(_:) ```

Create a set from a finite sequence of items. The sequence need not be sorted. If the sequence contains duplicate items, only the last instance will be kept in the set.

Complexity

O(n * log(n)), where n is the number of items in the sequence.

#### Declaration

Swift

``public init<S: Sequence>(_ elements: S) where S.Iterator.Element == Element``
• ``` init(sortedElements:) ```

Create a set from a sorted finite sequence of items. If the sequence contains duplicate items, only the last instance will be kept in the set.

Complexity

O(n), where n is the number of items in the sequence.

#### Declaration

Swift

``public init<S: Sequence>(sortedElements elements: S) where S.Iterator.Element == Element``
• ``` init(arrayLiteral:) ```

Create a set with the specified list of items. If the array literal contains duplicate items, only the last instance will be kept.

#### Declaration

Swift

``public init(arrayLiteral elements: Element...)``
• ``` subscript(_:) ```

Returns the element at the given index.

Requires

`index` originated from an unmutated copy of this set.

Complexity

O(1)

#### Declaration

Swift

``public subscript(index: Index) -> Element``
• ``` subscript(_:) ```

Return the subset consisting of elements in the given range of indexes.

Requires

The indices in `range` originated from an unmutated copy of this set.

Complexity

O(log(`count`))

#### Declaration

Swift

``public subscript(range: Range<Index>) -> SortedSet<Element>``
• ``` startIndex ```

The index of the first element when non-empty. Otherwise the same as `endIndex`.

Complexity

O(log(`count`))

#### Declaration

Swift

``public var startIndex: Index``
• ``` endIndex ```

The past-the-end element index; the successor of the last valid subscript argument.

Complexity

O(1)

#### Declaration

Swift

``public var endIndex: Index``
• ``` count ```

The number of elements in this set.

#### Declaration

Swift

``public var count: Int``
• ``` isEmpty ```

True iff this collection has no elements.

#### Declaration

Swift

``public var isEmpty: Bool``
• ``` makeIterator() ```

Return an iterator over all elements in this map, in ascending key order.

#### Declaration

Swift

``public func makeIterator() -> Iterator``
• ``` index(after:) ```

Returns the successor of the given index.

Requires

`index` is a valid index of this set and it is not equal to `endIndex`.

Complexity

Amortized O(1).

#### Declaration

Swift

``public func index(after index: Index) -> Index``
• ``` formIndex(after:) ```

Replaces the given index with its successor.

Requires

`index` is a valid index of this set and it is not equal to `endIndex`.

Complexity

Amortized O(1).

#### Declaration

Swift

``public func formIndex(after index: inout Index)``
• ``` index(before:) ```

Returns the predecessor of the given index.

Requires

`index` is a valid index of this set and it is not equal to `startIndex`.

Complexity

Amortized O(1).

#### Declaration

Swift

``public func index(before index: Index) -> Index``
• ``` formIndex(before:) ```

Replaces the given index with its predecessor.

Requires

`index` is a valid index of this set and it is not equal to `startIndex`.

Complexity

Amortized O(1).

#### Declaration

Swift

``public func formIndex(before index: inout Index)``
• ``` index(_:offsetBy:) ```

Returns an index that is at the specified distance from the given index.

Requires

`index` must be a valid index of this set. If `n` is positive, it must not exceed the distance from `index` to `endIndex`. If `n` is negative, it must not be less than the distance from `index` to `startIndex`.

Complexity

O(log(count)) where count is the number of elements in the set.

#### Declaration

Swift

``public func index(_ i: Index, offsetBy n: Int) -> Index``
• ``` formIndex(_:offsetBy:) ```

Offsets the given index by the specified distance.

Requires

`index` must be a valid index of this set. If `n` is positive, it must not exceed the distance from `index` to `endIndex`. If `n` is negative, it must not be less than the distance from `index` to `startIndex`.

Complexity

O(log(count)) where count is the number of elements in the set.

#### Declaration

Swift

``public func formIndex(_ i: inout Index, offsetBy n: Int)``
• ``` index(_:offsetBy:limitedBy:) ```

Returns an index that is at the specified distance from the given index, unless that distance is beyond a given limiting index.

Requires

`index` and `limit` must be valid indices in this set. The operation must not advance the index beyond `endIndex` or before `startIndex`.

Complexity

O(log(count)) where count is the number of elements in the set.

#### Declaration

Swift

``public func index(_ i: Index, offsetBy n: Int, limitedBy limit: Index) -> Index?``
• ``` formIndex(_:offsetBy:limitedBy:) ```

Offsets the given index by the specified distance, or so that it equals the given limiting index.

Requires

`index` and `limit` must be valid indices in this set. The operation must not advance the index beyond `endIndex` or before `startIndex`.

Complexity

O(log(count)) where count is the number of elements in the set.

#### Declaration

Swift

``public func formIndex(_ i: inout Index, offsetBy n: Int, limitedBy limit: Index) -> Bool``
• ``` distance(from:to:) ```

Returns the distance between two indices.

Requires

`start` and `end` must be valid indices in this set.

Complexity

O(1)

#### Declaration

Swift

``public func distance(from start: Index, to end: Index) -> Int``
• ``` subscript(_:) ```

Returns the element at `offset` from the start of the set.

Complexity

O(log(`count`))

#### Declaration

Swift

``public subscript(offset: Int) -> Element``
• ``` subscript(_:) ```

Returns the subset containing elements in the specified range of offsets from the start of the set.

Complexity

O(log(`count`))

#### Declaration

Swift

``public subscript(offsetRange: Range<Int>) -> SortedSet<Element>``
• ``` offset(of:) ```

Return the offset of `member`, if it is an element of this set. Otherwise, return `nil`.

Complexity

O(log(`count`))

#### Declaration

Swift

``public func offset(of member: Element) -> Int?``
• ``` index(ofOffset:) ```

Returns the offset of the element at `index`.

Complexity

O(log(`count`))

#### Declaration

Swift

``public func index(ofOffset offset: Int) -> Index``
• ``` offset(of:) ```

Returns the index of the element at `offset`.

Requires

`offset >= 0 && offset < count`

Complexity

O(log(`count`))

#### Declaration

Swift

``public func offset(of index: Index) -> Int``
• ``` forEach(_:) ```

Call `body` on each element in `self` in ascending order.

#### Declaration

Swift

``public func forEach(_ body: (Element) throws -> Void) rethrows``
• ``` map(_:) ```

Return an `Array` containing the results of mapping transform over `self`.

#### Declaration

Swift

``public func map<T>(_ transform: (Element) throws -> T) rethrows -> [T]``
• ``` flatMap(_:) ```

Return an `Array` containing the concatenated results of mapping `transform` over `self`.

#### Declaration

Swift

``public func flatMap<S : Sequence>(_ transform: (Element) throws -> S) rethrows -> [S.Iterator.Element]``
• ``` flatMap(_:) ```

Return an `Array` containing the non-`nil` results of mapping `transform` over `self`.

#### Declaration

Swift

``public func flatMap<T>(_ transform: (Element) throws -> T?) rethrows -> [T]``
• ``` filter(_:) ```

Return an `Array` containing the elements of `self`, in ascending order, that satisfy the predicate `includeElement`.

#### Declaration

Swift

``public func filter(_ includeElement: (Element) throws -> Bool) rethrows -> [Element]``
• ``` reduce(_:_:) ```

Return the result of repeatedly calling `combine` with an accumulated value initialized to `initial` and each element of `self`, in turn. I.e., return `combine(combine(...combine(combine(initial, self), self),...self[count-2]), self[count-1])`.

#### Declaration

Swift

``public func reduce<T>(_ initialResult: T, _ nextPartialResult: (T, Element) throws -> T) rethrows -> T``
• ``` first ```

Return the smallest element in the set, or `nil` if the set is empty.

Complexity

O(log(`count`))

#### Declaration

Swift

``public var first: Element?``
• ``` last ```

Return the largest element in the set, or `nil` if the set is empty.

Complexity

O(log(`count`))

#### Declaration

Swift

``public var last: Element?``
• ``` min() ```

Return the smallest element in the set, or `nil` if the set is empty.

Complexity

O(log(`count`))

#### Declaration

Swift

``public func min() -> Element?``
• ``` max() ```

Return the largest element in the set, or `nil` if the set is empty.

Complexity

O(log(`count`))

#### Declaration

Swift

``public func max() -> Element?``
• ``` dropFirst() ```

Return a copy of this set with the smallest element removed. If this set is empty, the result is an empty set.

Complexity

O(log(`count`))

#### Declaration

Swift

``public func dropFirst() -> SortedSet``
• ``` dropFirst(_:) ```

Return a copy of this set with the `n` smallest elements removed. If `n` exceeds the number of elements in the set, the result is an empty set.

Complexity

O(log(`count`))

#### Declaration

Swift

``public func dropFirst(_ n: Int) -> SortedSet``
• ``` dropLast() ```

Return a copy of this set with the largest element removed. If this set is empty, the result is an empty set.

Complexity

O(log(`count`))

#### Declaration

Swift

``public func dropLast() -> SortedSet``
• ``` dropLast(_:) ```

Return a copy of this set with the `n` largest elements removed. If `n` exceeds the number of elements in the set, the result is an empty set.

Complexity

O(log(`count`))

#### Declaration

Swift

``public func dropLast(_ n: Int) -> SortedSet``
• ``` prefix(_:) ```

Returns a subset, up to `maxLength` in size, containing the smallest elements in this set.

If `maxLength` exceeds the number of elements, the result contains all the elements of `self`.

Complexity

O(log(`count`))

#### Declaration

Swift

``public func prefix(_  maxLength: Int) -> SortedSet``
• ``` prefix(through:) ```

Returns a subset containing all members of this set at or before the specified index.

Complexity

O(log(`count`))

#### Declaration

Swift

``public func prefix(through index: Index) -> SortedSet``
• ``` prefix(through:) ```

Returns a subset containing all members of this set less than or equal to the specified element (which may or may not be a member of this set).

Complexity

O(log(`count`))

#### Declaration

Swift

``public func prefix(through element: Element) -> SortedSet``
• ``` prefix(upTo:) ```

Returns a subset containing all members of this set before the specified index.

Complexity

O(log(`count`))

#### Declaration

Swift

``public func prefix(upTo end: Index) -> SortedSet``
• ``` prefix(upTo:) ```

Returns a subset containing all members of this set less than the specified element (which may or may not be a member of this set).

Complexity

O(log(`count`))

#### Declaration

Swift

``public func prefix(upTo end: Element) -> SortedSet``
• ``` suffix(_:) ```

Returns a subset, up to `maxLength` in size, containing the largest elements in this set.

If `maxLength` exceeds `self.count`, the result contains all the elements of `self`.

Complexity

O(log(`count`))

#### Declaration

Swift

``public func suffix(_ maxLength: Int) -> SortedSet``
• ``` suffix(from:) ```

Returns a subset containing all members of this set at or after the specified index.

Complexity

O(log(`count`))

#### Declaration

Swift

``public func suffix(from index: Index) -> SortedSet``
• ``` suffix(from:) ```

Returns a subset containing all members of this set greater than or equal to the specified element (which may or may not be a member of this set).

Complexity

O(log(`count`))

#### Declaration

Swift

``public func suffix(from element: Element) -> SortedSet``
• ``` description ```

A textual representation of this set.

#### Declaration

Swift

``public var description: String``
• ``` debugDescription ```

A textual representation of this set, suitable for debugging.

#### Declaration

Swift

``public var debugDescription: String``
• ``` contains(_:) ```

Return true if the set contains `element`.

Complexity

O(log(`count`))

#### Declaration

Swift

``public func contains(_ element: Element) -> Bool``
• ``` index(of:) ```

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

Complexity

O(log(`count`))

#### Declaration

Swift

``public func index(of member: Element) -> BTreeIndex<Element, Void>?``
• ``` indexOfFirstElement(after:) ```

Returns the index of the lowest member of this set that is strictly greater than `element`, or `nil` if there is no such element.

This function never returns `endIndex`. (If it returns non-nil, the returned index can be used to subscript the set.)

Complexity

O(log(`count`))

#### Declaration

Swift

``public func indexOfFirstElement(after element: Element) -> BTreeIndex<Element, Void>?``
• ``` indexOfFirstElement(notBefore:) ```

Returns the index of the lowest member of this set that is greater than or equal to `element`, or `nil` if there is no such element.

This function never returns `endIndex`. (If it returns non-nil, the returned index can be used to subscript the set.)

Complexity

O(log(`count`))

#### Declaration

Swift

``public func indexOfFirstElement(notBefore element: Element) -> BTreeIndex<Element, Void>?``
• ``` indexOfLastElement(before:) ```

Returns the index of the highest member of this set that is strictly less than `element`, or `nil` if there is no such element.

This function never returns `endIndex`. (If it returns non-nil, the returned index can be used to subscript the set.)

Complexity

O(log(`count`))

#### Declaration

Swift

``public func indexOfLastElement(before element: Element) -> BTreeIndex<Element, Void>?``
• ``` indexOfLastElement(notAfter:) ```

Returns the index of the highest member of this set that is less than or equal to `element`, or `nil` if there is no such element.

This function never returns `endIndex`. (If it returns non-nil, the returned index can be used to subscript the set.)

Complexity

O(log(`count`))

#### Declaration

Swift

``public func indexOfLastElement(notAfter element: Element) -> BTreeIndex<Element, Void>?``
• ``` elementsEqual(_:) ```

Return `true` iff `self` and `other` contain the same elements.

This method skips over shared subtrees when possible; this can drastically improve performance when the two sets are divergent mutations originating from the same value.

Complexity

O(`count`)

#### Declaration

Swift

``public func elementsEqual(_ other: SortedSet<Element>) -> Bool``
• ``` ==(_:_:) ```

Returns `true` iff `a` contains the same elements as `b`.

This function skips over shared subtrees when possible; this can drastically improve performance when the two sets are divergent mutations originating from the same value.

Complexity

O(`count`)

#### Declaration

Swift

``public static func ==(a: SortedSet<Element>, b: SortedSet<Element>) -> Bool``
• ``` isDisjoint(with:) ```

Returns `true` iff no members in this set are also included in `other`.

The elements of the two input sets may be freely interleaved. However, if there are long runs of non-interleaved elements, parts of the input sets will be simply linked into the result instead of copying, which can drastically improve performance.

Complexity

• O(min(`self.count`, `other.count`)) in general.
• O(log(`self.count` + `other.count`)) if there are only a constant amount of interleaving element runs.

#### Declaration

Swift

``public func isDisjoint(with other: SortedSet<Element>) -> Bool``
• ``` isSubset(of:) ```

Returns `true` iff all members in this set are also included in `other`.

The elements of the two input sets may be freely interleaved. However, if there are long runs of non-interleaved elements, parts of the input sets will be simply linked into the result instead of copying, which can drastically improve performance.

Complexity

• O(min(`self.count`, `other.count`)) in general.
• O(log(`self.count` + `other.count`)) if there are only a constant amount of interleaving element runs.

#### Declaration

Swift

``public func isSubset(of other: SortedSet<Element>) -> Bool``
• ``` isStrictSubset(of:) ```

Returns `true` iff all members in this set are also included in `other`, but the two sets aren’t equal.

The elements of the two input sets may be freely interleaved. However, if there are long runs of non-interleaved elements, parts of the input sets may be skipped instead of elementwise processing, which can drastically improve performance.

Complexity

• O(min(`self.count`, `other.count`)) in general.
• O(log(`self.count` + `other.count`)) if there are only a constant amount of interleaving element runs.

#### Declaration

Swift

``public func isStrictSubset(of other: SortedSet<Element>) -> Bool``
• ``` isSuperset(of:) ```

Returns `true` iff all members in `other` are also included in this set.

The elements of the two input sets may be freely interleaved. However, if there are long runs of non-interleaved elements, parts of the input sets may be skipped instead of elementwise processing, which can drastically improve performance.

Complexity

• O(min(`self.count`, `other.count`)) in general.
• O(log(`self.count` + `other.count`)) if there are only a constant amount of interleaving element runs.

#### Declaration

Swift

``public func isSuperset(of other: SortedSet<Element>) -> Bool``
• ``` isStrictSuperset(of:) ```

Returns `true` iff all members in `other` are also included in this set, but the two sets aren’t equal.

The elements of the two input sets may be freely interleaved. However, if there are long runs of non-interleaved elements, parts of the input sets may be skipped instead of elementwise processing, which can drastically improve performance.

Complexity

• O(min(`self.count`, `other.count`)) in general.
• O(log(`self.count` + `other.count`)) if there are only a constant amount of interleaving element runs.

#### Declaration

Swift

``public func isStrictSuperset(of other: SortedSet<Element>) -> Bool``
• ``` insert(_:) ```

Insert a member into the set if it is not already present.

Returns

`(true, newMember)` if `newMember` was not contained in the set. If an element equal to `newMember` was already contained in the set, the method returns `(false, oldMember)`, where `oldMember` is the element that was equal to `newMember`. In some cases, `oldMember` may be distinguishable from `newMember` by identity comparison or some other means.

Complexity

O(log(`count`))

#### Declaration

Swift

``public mutating func insert(_ newMember: Element) -> (inserted: Bool, memberAfterInsert: Element)``

#### Return Value

`(true, newMember)` if `newMember` was not contained in the set. If an element equal to `newMember` was already contained in the set, the method returns `(false, oldMember)`, where `oldMember` is the element that was equal to `newMember`. In some cases, `oldMember` may be distinguishable from `newMember` by identity comparison or some other means.

• ``` update(with:) ```

Inserts the given element into the set unconditionally.

If an element equal to `newMember` is already contained in the set, `newMember` replaces the existing element.

Parameter

Parameter newMember: An element to insert into the set.

Returns

The element equal to `newMember` that was originally in the set, if exists; otherwise, `nil`. In some cases, the returned element may be distinguishable from `newMember` by identity comparison or some other means.

#### Declaration

Swift

``public mutating func update(with newMember: Element) -> Element?``

#### Parameters

 ``` newMember ``` An element to insert into the set.

#### Return Value

The element equal to `newMember` that was originally in the set, if exists; otherwise, `nil`. In some cases, the returned element may be distinguishable from `newMember` by identity comparison or some other means.

• ``` remove(_:) ```

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

Complexity

O(log(`count`))

#### Declaration

Swift

``public mutating func remove(_ element: Element) -> Element?``
• ``` remove(at:) ```

Remove the member referenced by the given index.

Complexity

O(log(`count`))

#### Declaration

Swift

``public mutating func remove(at index: Index) -> Element``
• ``` remove(atOffset:) ```

Remove the member at the given offset.

Complexity

O(log(`count`))

#### Declaration

Swift

``public mutating func remove(atOffset offset: Int) -> Element``
• ``` popFirst() ```

Remove and return the smallest member in this set, or return `nil` if the set is empty.

Complexity

O(log(`count`))

#### Declaration

Swift

``public mutating func popFirst() -> Element?``
• ``` popLast() ```

Remove and return the largest member in this set, or return `nil` if the set is empty.

Complexity

O(log(`count`))

#### Declaration

Swift

``public mutating func popLast() -> Element?``
• ``` removeAll() ```

Remove all members from this set.

#### Declaration

Swift

``public mutating func removeAll()``
• ``` sorted() ```

Return an `Array` containing the members of this set, in ascending order.

`SortedSet` already keeps its elements sorted, so this is equivalent to `Array(self)`.

Complexity

O(`count`)

#### Declaration

Swift

``public func sorted() -> [Element]``
• ``` union(_:) ```

Return a set containing all members in both this set and `other`.

The elements of the two input sets may be freely interleaved. However, if there are long runs of non-interleaved elements, parts of the input sets will be simply linked into the result instead of copying, which can drastically improve performance.

Complexity

• O(min(`self.count`, `other.count`)) in general.
• O(log(`self.count` + `other.count`)) if there are only a constant amount of interleaving element runs.

#### Declaration

Swift

``public func union(_ other: SortedSet<Element>) -> SortedSet<Element>``
• ``` intersection(_:) ```

Return a set consisting of all members in `other` that are also in this set.

The elements of the two input sets may be freely interleaved. However, if there are long runs of non-interleaved elements, parts of the input sets will be simply linked into the result instead of copying, which can drastically improve performance.

Complexity

• O(min(`self.count`, `other.count`)) in general.
• O(log(`self.count` + `other.count`)) if there are only a constant amount of interleaving element runs.

#### Declaration

Swift

``public func intersection(_ other: SortedSet<Element>) -> SortedSet<Element>``
• ``` symmetricDifference(_:) ```

Return a set consisting of members from `self` and `other` that aren’t in both sets at once.

The elements of the two input sets may be freely interleaved. However, if there are long runs of non-interleaved elements, parts of the input sets will be simply linked into the result instead of copying, which can drastically improve performance.

Complexity

• O(min(`self.count`, `other.count`)) in general.
• O(log(`self.count` + `other.count`)) if there are only a constant amount of interleaving element runs.

#### Declaration

Swift

``public func symmetricDifference(_ other: SortedSet<Element>) -> SortedSet<Element>``
• ``` formUnion(_:) ```

Add all members in `other` to this set.

The elements of the two input sets may be freely interleaved. However, if there are long runs of non-interleaved elements, parts of the input sets will be simply linked into the result instead of copying, which can drastically improve performance.

Complexity

• O(min(`self.count`, `other.count`)) in general.
• O(log(`self.count` + `other.count`)) if there are only a constant amount of interleaving element runs.

#### Declaration

Swift

``public mutating func formUnion(_ other: SortedSet<Element>)``
• ``` formIntersection(_:) ```

Remove all members from this set that are not included in `other`.

The elements of the two input sets may be freely interleaved. However, if there are long runs of non-interleaved elements, parts of the input sets will be simply linked into the result instead of copying, which can drastically improve performance.

Complexity

• O(min(`self.count`, `other.count`)) in general.
• O(log(`self.count` + `other.count`)) if there are only a constant amount of interleaving element runs.

#### Declaration

Swift

``public mutating func formIntersection(_ other: SortedSet<Element>)``
• ``` formSymmetricDifference(_:) ```

Replace `self` with a set consisting of members from `self` and `other` that aren’t in both sets at once.

The elements of the two input sets may be freely interleaved. However, if there are long runs of non-interleaved elements, parts of the input sets will be simply linked into the result instead of copying, which can drastically improve performance.

Complexity

• O(min(`self.count`, `other.count`)) in general.
• O(log(`self.count` + `other.count`)) if there are only a constant amount of interleaving element runs.

#### Declaration

Swift

``public mutating func formSymmetricDifference(_ other: SortedSet<Element>)``
• ``` subtracting(_:) ```

Return a set containing those members of this set that aren’t also included in `other`.

The elements of the two input sets may be freely interleaved. However, if there are long runs of non-interleaved elements, parts of the input sets will be simply linked into the result instead of copying, which can drastically improve performance.

Complexity

• O(min(`self.count`, `other.count`)) in general.
• O(log(`self.count` + `other.count`)) if there are only a constant amount of interleaving element runs.

#### Declaration

Swift

``public func subtracting(_ other: SortedSet) -> SortedSet``
• ``` subtract(_:) ```

Remove all members from this set that are also included in `other`.

The elements of the two input sets may be freely interleaved. However, if there are long runs of non-interleaved elements, parts of the input sets will be simply linked into the result instead of copying, which can drastically improve performance.

Complexity

• O(min(`self.count`, `other.count`)) in general.
• O(log(`self.count` + `other.count`)) if there are only a constant amount of interleaving element runs.

#### Declaration

Swift

``public mutating func subtract(_ other: SortedSet)``
• ``` count(elementsIn:) ```

Return the count of elements in this set that are in `range`.

Complexity

O(log(`self.count`))

#### Declaration

Swift

``public func count(elementsIn range: Range<Element>) -> Int``
• ``` count(elementsIn:) ```

Return the count of elements in this set that are in `range`.

Complexity

O(log(`self.count`))

#### Declaration

Swift

``public func count(elementsIn range: ClosedRange<Element>) -> Int``
• ``` intersection(elementsIn:) ```

Return a set consisting of all members in `self` that are also in `range`.

Complexity

O(log(`self.count`))

#### Declaration

Swift

``public func intersection(elementsIn range: Range<Element>) -> SortedSet<Element>``
• ``` intersection(elementsIn:) ```

Return a set consisting of all members in `self` that are also in `range`.

Complexity

O(log(`self.count`))

#### Declaration

Swift

``public func intersection(elementsIn range: ClosedRange<Element>) -> SortedSet<Element>``
• ``` formIntersection(elementsIn:) ```

Remove all members from this set that are not included in `range`.

Complexity

O(log(`self.count`))

#### Declaration

Swift

``public mutating func formIntersection(elementsIn range: Range<Element>)``
• ``` formIntersection(elementsIn:) ```

Remove all members from this set that are not included in `range`.

Complexity

O(log(`self.count`))

#### Declaration

Swift

``public mutating func formIntersection(elementsIn range: ClosedRange<Element>)``
• ``` subtract(elementsIn:) ```

Remove all elements in `range` from this set.

Complexity

O(log(`self.count`))

#### Declaration

Swift

``public mutating func subtract(elementsIn range: Range<Element>)``
• ``` subtract(elementsIn:) ```

Remove all elements in `range` from this set.

Complexity

O(log(`self.count`))

#### Declaration

Swift

``public mutating func subtract(elementsIn range: ClosedRange<Element>)``
• ``` subtracting(elementsIn:) ```

Return a set containing those members of this set that aren’t also included in `range`.

Complexity

O(log(`self.count`))

#### Declaration

Swift

``public mutating func subtracting(elementsIn range: Range<Element>) -> SortedSet<Element>``
• ``` subtracting(elementsIn:) ```

Return a set containing those members of this set that aren’t also included in `range`.

Complexity

O(log(`self.count`))

#### Declaration

Swift

``public mutating func subtracting(elementsIn range: ClosedRange<Element>) -> SortedSet<Element>``
• ``` shift(startingAt:by:) ```

Shift the value of all elements starting at `start` by `delta`. For a positive `delta`, this shifts elements to the right, creating an empty gap in `start ..< start + delta`. For a negative `delta`, this shifts elements to the left, removing any elements in the range `start + delta ..< start` that were previously in the set.

Complexity

O(`self.count`). The elements are modified in place.

#### Declaration

Swift

``public mutating func shift(startingAt start: Element, by delta: Element.Stride)``