Skip to content

Commit b467e24

Browse files
committed
Apply public documentation and type modifications from proposal acceptance
1 parent df3a058 commit b467e24

File tree

5 files changed

+70
-406
lines changed

5 files changed

+70
-406
lines changed

stdlib/public/core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,11 @@ set(SWIFTLIB_SOURCES
201201
${SWIFTLIB_ESSENTIAL}
202202
### PLEASE KEEP THIS LIST IN ALPHABETICAL ORDER ###
203203
Availability.swift
204+
CollectionDifference.swift
204205
CollectionOfOne.swift
205206
Diffing.swift
206207
ExistentialCollection.swift.gyb
207208
Mirror.swift
208-
OrderedCollectionDifference.swift
209209
PlaygroundDisplay.swift
210210
CommandLine.swift
211211
SliceBuffer.swift

stdlib/public/core/Diffing.swift

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414

1515
extension RangeReplaceableCollection {
1616
private static func fastApplicationEnumeration(
17-
of diff: OrderedCollectionDifference<Element>,
18-
_ f: (OrderedCollectionDifference<Element>.Change) -> Void
17+
of diff: CollectionDifference<Element>,
18+
_ f: (CollectionDifference<Element>.Change) -> Void
1919
) {
2020
let totalRemoves = diff.removals.count
2121
let totalInserts = diff.insertions.count
2222
var enumeratedRemoves = 0
2323
var enumeratedInserts = 0
2424

2525
while enumeratedRemoves < totalRemoves || enumeratedInserts < totalInserts {
26-
let consume: OrderedCollectionDifference<Element>.Change
26+
let consume: CollectionDifference<Element>.Change
2727
if enumeratedRemoves < diff.removals.count && enumeratedInserts < diff.insertions.count {
2828
let removeOffset = diff.removals[enumeratedRemoves].offset
2929
let insertOffset = diff.insertions[enumeratedInserts].offset
@@ -62,8 +62,8 @@ extension RangeReplaceableCollection {
6262
///
6363
/// - Complexity: O(*n* + *c*), where *n* is `self.count` and *c* is the
6464
/// number of changes contained by the parameter.
65-
// @available(swift, introduced: 5.1)
66-
public func applying(_ difference: OrderedCollectionDifference<Element>) -> Self? {
65+
@available(swift, introduced: 5.1)
66+
public func applying(_ difference: CollectionDifference<Element>) -> Self? {
6767
var result = Self()
6868
var enumeratedRemoves = 0
6969
var enumeratedInserts = 0
@@ -105,34 +105,31 @@ extension RangeReplaceableCollection {
105105

106106
// MARK: Definition of API
107107

108-
//@available(swift, introduced: 5.1)
108+
@available(swift, introduced: 5.1)
109109
extension BidirectionalCollection {
110110
/// Returns the difference needed to produce the receiver's state from the
111-
/// parameter's state with the fewest possible changes, using the provided
112-
/// closure to establish equivalence between elements.
111+
/// parameter's state, using the provided closure to establish equivalence
112+
/// between elements.
113113
///
114-
/// This function does not infer element moves, but they can be computed
115-
/// using `OrderedCollectionDifference.inferringMoves()` if desired.
116-
///
117-
/// Implementation is an optimized variation of the algorithm described by
118-
/// E. Myers (1986).
114+
/// This function does not infer moves.
119115
///
120116
/// - Parameters:
121117
/// - other: The base state.
122118
/// - areEquivalent: A closure that returns whether the two
123-
/// parameters are equivalent.
119+
/// parameters are equivalent.
124120
///
125121
/// - Returns: The difference needed to produce the reciever's state from
126122
/// the parameter's state.
127123
///
128-
/// - Complexity: O(*n* * *d*), where *n* is `other.count + self.count` and
129-
/// *d* is the number of changes between the two ordered collections.
124+
/// - Complexity: For pathological inputs, worst case performance is
125+
/// O(`self.count` * `other.count`). Faster execution can be expected
126+
/// when the collections share many common elements.
130127
public func difference<C>(
131128
from other: C, by areEquivalent: (Element, C.Element) -> Bool
132-
) -> OrderedCollectionDifference<Element>
129+
) -> CollectionDifference<Element>
133130
where C : BidirectionalCollection, C.Element == Self.Element
134131
{
135-
var rawChanges: [OrderedCollectionDifference<Element>.Change] = []
132+
var rawChanges: [CollectionDifference<Element>.Change] = []
136133

137134
let source = CountingIndexCollection(other)
138135
let target = CountingIndexCollection(self)
@@ -159,30 +156,29 @@ extension BidirectionalCollection {
159156
}
160157
}
161158

162-
return OrderedCollectionDifference<Element>(validatedChanges: rawChanges)
159+
return CollectionDifference<Element>(validatedChanges: rawChanges)
163160
}
164161
}
165162

166163
extension BidirectionalCollection where Element : Equatable {
167164
/// Returns the difference needed to produce the receiver's state from the
168-
/// parameter's state with the fewest possible changes, using equality to
169-
/// establish equivalence between elements.
165+
/// parameter's state, using equality to establish equivalence between
166+
/// elements.
170167
///
171168
/// This function does not infer element moves, but they can be computed
172-
/// using `OrderedCollectionDifference.inferringMoves()` if desired.
173-
///
174-
/// Implementation is an optimized variation of the algorithm described by
175-
/// E. Myers (1986).
169+
/// using `CollectionDifference.inferringMoves()` if desired.
176170
///
177171
/// - Parameters:
178172
/// - other: The base state.
179173
///
180174
/// - Returns: The difference needed to produce the reciever's state from
181175
/// the parameter's state.
182176
///
183-
/// - Complexity: O(*n* * *d*), where *n* is `other.count + self.count` and
184-
/// *d* is the number of changes between the two ordered collections.
185-
public func difference<C>(from other: C) -> OrderedCollectionDifference<Element>
177+
/// - Complexity: For pathological inputs, worst case performance is
178+
/// O(`self.count` * `other.count`). Faster execution can be expected
179+
/// when the collections share many common elements, or if `Element`
180+
/// also conforms to `Hashable`.
181+
public func difference<C>(from other: C) -> CollectionDifference<Element>
186182
where C: BidirectionalCollection, C.Element == Self.Element
187183
{
188184
return difference(from: other, by: ==)

stdlib/public/core/GroupInfo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
"UIntBuffer.swift",
8484
"KeyValuePairs.swift",
8585
"Diffing.swift",
86-
"OrderedCollectionDifference.swift",
86+
"CollectionDifference.swift",
8787
{
8888
"Type-erased": [
8989
"ExistentialCollection.swift"

0 commit comments

Comments
 (0)