Skip to content

Commit 6cb8350

Browse files
authored
---
yaml --- r: 294271 b: refs/heads/tensorflow c: 841eb4c h: refs/heads/master i: 294269: db570fa 294267: bc77be0 294263: 9c6ae5e 294255: 791f97f 294239: 897bbe6 294207: 00e11ba 294143: 4e34cbd
1 parent f870349 commit 6cb8350

File tree

3 files changed

+55
-46
lines changed

3 files changed

+55
-46
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-04-25-a: 22f738a831d43aff2b9c9773bcb65
816816
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-05-08-a: 7d98cc16689baba5c8a3b90a9329bdcc1a12b4e9
817817
refs/heads/cherr42: a566ad54b073c2c56ac0a705d0a5bed9743135a5
818818
"refs/heads/codable_test_comment_fix": fc8f6824f7f347e1e8db55bff62db385c5728b5a
819-
refs/heads/tensorflow: 14a20eea03e9115e2c5cf91bccc86e6cd5334df9
819+
refs/heads/tensorflow: 841eb4cf5eaacaef70132db56f69441533a5127e
820820
refs/tags/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-05-11-a: 8126fd7a652e2f70ad6d76505239e34fb2ef3e1a
821821
refs/tags/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-05-12-a: b3fd3dd84df6717f2e2e9df58c6d7e99fed57086
822822
refs/tags/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-05-13-a: 71135119579039dc321c5f65d870050fe36efda2

branches/tensorflow/stdlib/public/core/CollectionDifference.swift

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,26 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
/// A type that represents the difference between two ordered collection states.
13+
/// A collection of insertions and removals that describe the difference
14+
/// between two ordered collection states.
1415
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *) // FIXME(availability-5.1)
1516
public struct CollectionDifference<ChangeElement> {
16-
/// A type that represents a single change to a collection.
17-
///
18-
/// The `offset` of each `insert` refers to the offset of its `element` in
19-
/// the final state after the difference is fully applied. The `offset` of
20-
/// each `remove` refers to the offset of its `element` in the original
21-
/// state. Non-`nil` values of `associatedWith` refer to the offset of the
22-
/// complementary change.
17+
/// A single change to a collection.
2318
@_frozen
2419
public enum Change {
20+
/// An insertion.
21+
///
22+
/// The `offset` value is the offset of the inserted element in the final
23+
/// state of the collection after the difference is fully applied.
24+
/// A non-`nil` `associatedWith` value is the offset of the complementary
25+
/// change.
2526
case insert(offset: Int, element: ChangeElement, associatedWith: Int?)
27+
28+
/// A removal.
29+
///
30+
/// The `offset` value is the offset of the element to be removed in the
31+
/// original state of the collection. A non-`nil` `associatedWith` value is
32+
/// the offset of the complementary change.
2633
case remove(offset: Int, element: ChangeElement, associatedWith: Int?)
2734

2835
// Internal common field accessors
@@ -58,10 +65,11 @@ public struct CollectionDifference<ChangeElement> {
5865
}
5966
}
6067

61-
/// The `.insert` changes contained by this difference, from lowest offset to highest
68+
/// The insertions contained by this difference, from lowest offset to
69+
/// highest.
6270
public let insertions: [Change]
6371

64-
/// The `.remove` changes contained by this difference, from lowest offset to highest
72+
/// The removals contained by this difference, from lowest offset to highest.
6573
public let removals: [Change]
6674

6775
/// The public initializer calls this function to ensure that its parameter
@@ -117,20 +125,20 @@ public struct CollectionDifference<ChangeElement> {
117125
return removeOffsetToAssoc == insertAssocToOffset
118126
}
119127

120-
/// Creates an instance from a collection of changes.
128+
/// Creates a new collection difference from a collection of changes.
121129
///
122-
/// For clients interested in the difference between two collections, see
123-
/// `BidirectionalCollection.difference(from:)`.
130+
/// To find the difference between two collections, use the
131+
/// `difference(from:)` method declared on the `BidirectionalCollection`
132+
/// protocol.
124133
///
125-
/// To guarantee that instances are unambiguous and safe for compatible base
126-
/// states, this initializer will fail unless its parameter meets to the
127-
/// following requirements:
134+
/// The collection of changes passed as `changes` must meet these
135+
/// requirements:
128136
///
129-
/// 1. All insertion offsets are unique
130-
/// 2. All removal offsets are unique
131-
/// 3. All associations between insertions and removals are symmetric
137+
/// - All insertion offsets are unique
138+
/// - All removal offsets are unique
139+
/// - All associations between insertions and removals are symmetric
132140
///
133-
/// - Parameter c: A collection of changes that represent a transition
141+
/// - Parameter changes: A collection of changes that represent a transition
134142
/// between two states.
135143
///
136144
/// - Complexity: O(*n* * log(*n*)), where *n* is the length of the
@@ -218,6 +226,7 @@ public struct CollectionDifference<ChangeElement> {
218226
extension CollectionDifference: Collection {
219227
public typealias Element = Change
220228

229+
/// The position of a collection difference.
221230
@_fixed_layout
222231
public struct Index {
223232
// Opaque index type is isomorphic to Int
@@ -305,12 +314,12 @@ extension CollectionDifference: Hashable where ChangeElement: Hashable {}
305314

306315
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *) // FIXME(availability-5.1)
307316
extension CollectionDifference where ChangeElement: Hashable {
308-
/// Infers which `ChangeElement`s have been both inserted and removed only
309-
/// once and returns a new difference with those associations.
317+
/// Returns a new collection difference with associations between individual
318+
/// elements that have been removed and inserted only once.
310319
///
311-
/// - Returns: an instance with all possible moves inferred.
320+
/// - Returns: An collection difference with all possible moves inferred.
312321
///
313-
/// - Complexity: O(*n*) where *n* is `self.count`
322+
/// - Complexity: O(*n*) where *n* is the number of collection differences.
314323
public func inferringMoves() -> CollectionDifference<ChangeElement> {
315324
let uniqueRemovals: [ChangeElement:Int?] = {
316325
var result = [ChangeElement:Int?](minimumCapacity: Swift.min(removals.count, insertions.count))

branches/tensorflow/stdlib/public/core/Diffing.swift

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ extension CollectionDifference {
5454
}
5555

5656
extension RangeReplaceableCollection {
57-
/// Applies a difference to a collection.
57+
/// Applies the given difference to this collection.
5858
///
5959
/// - Parameter difference: The difference to be applied.
6060
///
@@ -112,23 +112,24 @@ extension RangeReplaceableCollection {
112112
// MARK: Definition of API
113113

114114
extension BidirectionalCollection {
115-
/// Returns the difference needed to produce the receiver's state from the
116-
/// parameter's state, using the provided closure to establish equivalence
117-
/// between elements.
115+
/// Returns the difference needed to produce this collection's ordered
116+
/// elements from the given collection, using the given predicate as an
117+
/// equivalence test.
118118
///
119-
/// This function does not infer moves.
119+
/// This function does not infer element moves. If you need to infer moves,
120+
/// call the `inferringMoves()` method on the resulting difference.
120121
///
121122
/// - Parameters:
122123
/// - other: The base state.
123-
/// - areEquivalent: A closure that returns whether the two
124-
/// parameters are equivalent.
124+
/// - areEquivalent: A closure that returns a Boolean value indicating
125+
/// whether two elements are equivalent.
125126
///
126127
/// - Returns: The difference needed to produce the reciever's state from
127128
/// the parameter's state.
128129
///
129-
/// - Complexity: For pathological inputs, worst case performance is
130-
/// O(`self.count` * `other.count`). Faster execution can be expected
131-
/// when the collections share many common elements.
130+
/// - Complexity: Worst case performance is O(*n* * *m*), where *n* is the
131+
/// count of this collection and *m* is `other.count`. You can expect
132+
/// faster execution when the collections share many common elements.
132133
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *) // FIXME(availability-5.1)
133134
public func difference<C: BidirectionalCollection>(
134135
from other: C,
@@ -167,23 +168,22 @@ extension BidirectionalCollection {
167168
}
168169

169170
extension BidirectionalCollection where Element : Equatable {
170-
/// Returns the difference needed to produce the receiver's state from the
171-
/// parameter's state, using equality to establish equivalence between
172-
/// elements.
171+
/// Returns the difference needed to produce this collection's ordered
172+
/// elements from the given collection.
173173
///
174-
/// This function does not infer element moves, but they can be computed
175-
/// using `CollectionDifference.inferringMoves()` if desired.
174+
/// This function does not infer element moves. If you need to infer moves,
175+
/// call the `inferringMoves()` method on the resulting difference.
176176
///
177177
/// - Parameters:
178178
/// - other: The base state.
179179
///
180-
/// - Returns: The difference needed to produce the reciever's state from
181-
/// the parameter's state.
180+
/// - Returns: The difference needed to produce this collection's ordered
181+
/// elements from the given collection.
182182
///
183-
/// - Complexity: For pathological inputs, worst case performance is
184-
/// O(`self.count` * `other.count`). Faster execution can be expected
185-
/// when the collections share many common elements, or if `Element`
186-
/// also conforms to `Hashable`.
183+
/// - Complexity: Worst case performance is O(*n* * *m*), where *n* is the
184+
/// count of this collection and *m* is `other.count`. You can expect
185+
/// faster execution when the collections share many common elements, or
186+
/// if `Element` conforms to `Hashable`.
187187
@available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *) // FIXME(availability-5.1)
188188
public func difference<C: BidirectionalCollection>(
189189
from other: C

0 commit comments

Comments
 (0)