Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Guides/Partition.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,18 @@ The `partitioningIndex(where:)` method is available on any `Collection` type.

```swift
extension MutableCollection {
@discardableResult
mutating func stablePartition(
by belongsInSecondPartition: (Element) throws -> Bool
) rethrows -> Index

@discardableResult
mutating func stablePartition(
subrange: Range<Index>,
by belongsInSecondPartition: (Element) throws -> Bool
) rethrows -> Index

@discardableResult
mutating func partition(
subrange: Range<Index>,
by belongsInSecondPartition: (Element) throws -> Bool
Expand Down
5 changes: 5 additions & 0 deletions Sources/Algorithms/Partition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extension MutableCollection {
/// - Precondition:
/// `n == distance(from: range.lowerBound, to: range.upperBound)`
@inlinable
@discardableResult
internal mutating func stablePartition(
count n: Int,
subrange: Range<Index>,
Expand Down Expand Up @@ -63,6 +64,7 @@ extension MutableCollection {
///
/// - Complexity: O(*n* log *n*), where *n* is the length of this collection.
@inlinable
@discardableResult
public mutating func stablePartition(
subrange: Range<Index>,
by belongsInSecondPartition: (Element) throws -> Bool
Expand All @@ -87,6 +89,7 @@ extension MutableCollection {
///
/// - Complexity: O(*n* log *n*), where *n* is the length of this collection.
@inlinable
@discardableResult
public mutating func stablePartition(
by belongsInSecondPartition: (Element) throws -> Bool
) rethrows -> Index {
Expand Down Expand Up @@ -122,6 +125,7 @@ extension MutableCollection {
///
/// - Complexity: O(*n*) where n is the length of the collection.
@inlinable
@discardableResult
public mutating func partition(
subrange: Range<Index>,
by belongsInSecondPartition: (Element) throws -> Bool
Expand Down Expand Up @@ -166,6 +170,7 @@ extension MutableCollection where Self: BidirectionalCollection {
///
/// - Complexity: O(*n*) where n is the length of the collection.
@inlinable
@discardableResult
public mutating func partition(
subrange: Range<Index>,
by belongsInSecondPartition: (Element) throws -> Bool
Expand Down