MutableCollectionAlgorithms

public protocol MutableCollectionAlgorithms: MutableCollection
where SubSequence: MutableCollectionAlgorithms

Provides customization points for MutableCollection algorithms.

If incorporated into the standard library, these requirements would just be part of MutableCollection. In the meantime, you can declare conformance of a collection to MutableCollectionAlgorithms to get these customization points to be used from other algorithms defined on MutableCollectionAlgorithms.

  • Rotates the elements of the collection so that the element at middle ends up first.

    Complexity

    O(n)

    Declaration

    @discardableResult
    mutating mutating func rotate(shiftingToStart middle: Index) -> Index

    Return Value

    The new index of the element that was first pre-rotation.

  • Moves all elements satisfying isSuffixElement into a suffix of the collection, preserving their relative order, and returns the start of the resulting suffix.

    Complexity

    O(n) where n is the number of elements.

    Declaration

    @discardableResult
    mutating func stablePartition(
      isSuffixElement: (Element) throws -> Bool
    ) rethrows -> Index