11
11
//===----------------------------------------------------------------------===//
12
12
13
13
/// 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)
15
15
public struct CollectionDifference < ChangeElement> {
16
16
/// A type that represents a single change to a collection.
17
17
///
@@ -213,10 +213,11 @@ public struct CollectionDifference<ChangeElement> {
213
213
/// }
214
214
/// }
215
215
/// ```
216
+ @available ( macOS 9999 , iOS 9999 , tvOS 9999 , watchOS 9999 , * ) // FIXME(availability-5.1)
216
217
extension CollectionDifference : Collection {
217
218
public typealias Element = Change
218
219
219
- public struct Index {
220
+ public struct Index : Equatable , Hashable , Comparable {
220
221
// Opaque index type is isomorphic to Int
221
222
internal let _offset : Int
222
223
@@ -228,40 +229,37 @@ extension CollectionDifference: Collection {
228
229
public var startIndex : Index {
229
230
return Index ( _offset: 0 )
230
231
}
231
-
232
+
232
233
public var endIndex : Index {
233
234
return Index ( _offset: removals. count + insertions. count)
234
235
}
235
-
236
+
236
237
public func index( after index: Index ) -> Index {
237
238
return Index ( _offset: index. _offset + 1 )
238
239
}
239
-
240
+
240
241
public subscript( position: Index ) -> Element {
241
242
if position. _offset < removals. count {
242
243
return removals [ removals. count - ( position. _offset + 1 ) ]
243
244
}
244
245
return insertions [ position. _offset - removals. count]
245
246
}
246
-
247
+
247
248
public func index( before index: Index ) -> Index {
248
249
return Index ( _offset: index. _offset - 1 )
249
250
}
250
-
251
+
251
252
public func formIndex( _ index: inout Index , offsetBy distance: Int ) {
252
253
index = Index ( _offset: index. _offset + distance)
253
254
}
254
-
255
+
255
256
public func distance( from start: Index , to end: Index ) -> Int {
256
257
return end. _offset - start. _offset
257
258
}
258
259
}
259
260
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
265
263
public static func < (
266
264
lhs: CollectionDifference . Index ,
267
265
rhs: CollectionDifference . Index
@@ -270,14 +268,19 @@ extension CollectionDifference.Index: Comparable {
270
268
}
271
269
}
272
270
271
+ @available ( macOS 9999 , iOS 9999 , tvOS 9999 , watchOS 9999 , * ) // FIXME(availability-5.1)
273
272
extension CollectionDifference . Change : Equatable where ChangeElement: Equatable { }
274
273
274
+ @available ( macOS 9999 , iOS 9999 , tvOS 9999 , watchOS 9999 , * ) // FIXME(availability-5.1)
275
275
extension CollectionDifference : Equatable where ChangeElement: Equatable { }
276
276
277
+ @available ( macOS 9999 , iOS 9999 , tvOS 9999 , watchOS 9999 , * ) // FIXME(availability-5.1)
277
278
extension CollectionDifference . Change : Hashable where ChangeElement: Hashable { }
278
279
280
+ @available ( macOS 9999 , iOS 9999 , tvOS 9999 , watchOS 9999 , * ) // FIXME(availability-5.1)
279
281
extension CollectionDifference : Hashable where ChangeElement: Hashable { }
280
282
283
+ @available ( macOS 9999 , iOS 9999 , tvOS 9999 , watchOS 9999 , * ) // FIXME(availability-5.1)
281
284
extension CollectionDifference where ChangeElement: Hashable {
282
285
/// Infers which `ChangeElement`s have been both inserted and removed only
283
286
/// once and returns a new difference with those associations.
@@ -334,6 +337,7 @@ extension CollectionDifference where ChangeElement: Hashable {
334
337
}
335
338
}
336
339
340
+ @available ( macOS 9999 , iOS 9999 , tvOS 9999 , watchOS 9999 , * ) // FIXME(availability-5.1)
337
341
extension CollectionDifference . Change : Codable where ChangeElement: Codable {
338
342
private enum _CodingKeys : String , CodingKey {
339
343
case offset
@@ -354,7 +358,7 @@ extension CollectionDifference.Change: Codable where ChangeElement: Codable {
354
358
self = . insert( offset: offset, element: element, associatedWith: associatedOffset)
355
359
}
356
360
}
357
-
361
+
358
362
public func encode( to encoder: Encoder ) throws {
359
363
var container = encoder. container ( keyedBy: _CodingKeys. self)
360
364
switch self {
@@ -370,4 +374,5 @@ extension CollectionDifference.Change: Codable where ChangeElement: Codable {
370
374
}
371
375
}
372
376
377
+ @available ( macOS 9999 , iOS 9999 , tvOS 9999 , watchOS 9999 , * ) // FIXME(availability-5.1)
373
378
extension CollectionDifference : Codable where ChangeElement: Codable { }
0 commit comments