Skip to content

Commit 8432cdc

Browse files
committed
[stdlib] Set availability of diffing APIs
(cherry picked from commit fd32a3d)
1 parent 5024919 commit 8432cdc

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

stdlib/public/core/CollectionDifference.swift

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
/// A type that represents the difference between two ordered collection states.
14-
@available(swift, introduced: 5.1)
14+
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *) // FIXME(availability-5.1)
1515
public struct CollectionDifference<ChangeElement> {
1616
/// A type that represents a single change to a collection.
1717
///
@@ -213,10 +213,11 @@ public struct CollectionDifference<ChangeElement> {
213213
/// }
214214
/// }
215215
/// ```
216+
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *) // FIXME(availability-5.1)
216217
extension CollectionDifference: Collection {
217218
public typealias Element = Change
218219

219-
public struct Index {
220+
public struct Index: Equatable, Hashable, Comparable {
220221
// Opaque index type is isomorphic to Int
221222
internal let _offset: Int
222223

@@ -228,40 +229,37 @@ extension CollectionDifference: Collection {
228229
public var startIndex: Index {
229230
return Index(_offset: 0)
230231
}
231-
232+
232233
public var endIndex: Index {
233234
return Index(_offset: removals.count + insertions.count)
234235
}
235-
236+
236237
public func index(after index: Index) -> Index {
237238
return Index(_offset: index._offset + 1)
238239
}
239-
240+
240241
public subscript(position: Index) -> Element {
241242
if position._offset < removals.count {
242243
return removals[removals.count - (position._offset + 1)]
243244
}
244245
return insertions[position._offset - removals.count]
245246
}
246-
247+
247248
public func index(before index: Index) -> Index {
248249
return Index(_offset: index._offset - 1)
249250
}
250-
251+
251252
public func formIndex(_ index: inout Index, offsetBy distance: Int) {
252253
index = Index(_offset: index._offset + distance)
253254
}
254-
255+
255256
public func distance(from start: Index, to end: Index) -> Int {
256257
return end._offset - start._offset
257258
}
258259
}
259260

260-
extension CollectionDifference.Index: Equatable {} // synthesized
261-
262-
extension CollectionDifference.Index: Hashable {} // synthesized
263-
264-
extension CollectionDifference.Index: Comparable {
261+
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *) // FIXME(availability-5.1)
262+
extension CollectionDifference.Index { // Comparable
265263
public static func < (
266264
lhs: CollectionDifference.Index,
267265
rhs: CollectionDifference.Index
@@ -270,14 +268,19 @@ extension CollectionDifference.Index: Comparable {
270268
}
271269
}
272270

271+
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *) // FIXME(availability-5.1)
273272
extension CollectionDifference.Change: Equatable where ChangeElement: Equatable {}
274273

274+
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *) // FIXME(availability-5.1)
275275
extension CollectionDifference: Equatable where ChangeElement: Equatable {}
276276

277+
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *) // FIXME(availability-5.1)
277278
extension CollectionDifference.Change: Hashable where ChangeElement: Hashable {}
278279

280+
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *) // FIXME(availability-5.1)
279281
extension CollectionDifference: Hashable where ChangeElement: Hashable {}
280282

283+
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *) // FIXME(availability-5.1)
281284
extension CollectionDifference where ChangeElement: Hashable {
282285
/// Infers which `ChangeElement`s have been both inserted and removed only
283286
/// once and returns a new difference with those associations.
@@ -334,6 +337,7 @@ extension CollectionDifference where ChangeElement: Hashable {
334337
}
335338
}
336339

340+
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *) // FIXME(availability-5.1)
337341
extension CollectionDifference.Change: Codable where ChangeElement: Codable {
338342
private enum _CodingKeys: String, CodingKey {
339343
case offset
@@ -354,7 +358,7 @@ extension CollectionDifference.Change: Codable where ChangeElement: Codable {
354358
self = .insert(offset: offset, element: element, associatedWith: associatedOffset)
355359
}
356360
}
357-
361+
358362
public func encode(to encoder: Encoder) throws {
359363
var container = encoder.container(keyedBy: _CodingKeys.self)
360364
switch self {
@@ -370,4 +374,5 @@ extension CollectionDifference.Change: Codable where ChangeElement: Codable {
370374
}
371375
}
372376

377+
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *) // FIXME(availability-5.1)
373378
extension CollectionDifference: Codable where ChangeElement: Codable {}

stdlib/public/core/Diffing.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
// MARK: Diff application to RangeReplaceableCollection
1414

15+
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *) // FIXME(availability-5.1)
1516
extension CollectionDifference {
1617
fileprivate func _fastEnumeratedApply(
1718
_ consume: (Change) -> Void
@@ -63,7 +64,7 @@ extension RangeReplaceableCollection {
6364
///
6465
/// - Complexity: O(*n* + *c*), where *n* is `self.count` and *c* is the
6566
/// number of changes contained by the parameter.
66-
@available(swift, introduced: 5.1)
67+
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *) // FIXME(availability-5.1)
6768
public func applying(_ difference: CollectionDifference<Element>) -> Self? {
6869
var result = Self()
6970
var enumeratedRemoves = 0
@@ -109,7 +110,6 @@ extension RangeReplaceableCollection {
109110

110111
// MARK: Definition of API
111112

112-
@available(swift, introduced: 5.1)
113113
extension BidirectionalCollection {
114114
/// Returns the difference needed to produce the receiver's state from the
115115
/// parameter's state, using the provided closure to establish equivalence
@@ -128,6 +128,7 @@ extension BidirectionalCollection {
128128
/// - Complexity: For pathological inputs, worst case performance is
129129
/// O(`self.count` * `other.count`). Faster execution can be expected
130130
/// when the collections share many common elements.
131+
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *) // FIXME(availability-5.1)
131132
public func difference<C: BidirectionalCollection>(
132133
from other: C,
133134
by areEquivalent: (Element, C.Element) -> Bool
@@ -183,6 +184,7 @@ extension BidirectionalCollection where Element : Equatable {
183184
/// O(`self.count` * `other.count`). Faster execution can be expected
184185
/// when the collections share many common elements, or if `Element`
185186
/// also conforms to `Hashable`.
187+
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *) // FIXME(availability-5.1)
186188
public func difference<C: BidirectionalCollection>(
187189
from other: C
188190
) -> CollectionDifference<Element> where C.Element == Self.Element {

0 commit comments

Comments
 (0)