@@ -57,8 +57,20 @@ public struct CollectionDifference<ChangeElement> {
57
57
}
58
58
}
59
59
60
- // The public initializer calls this function to ensure that its parameter
61
- // meets the conditions set in its documentation.
60
+ /// The public initializer calls this function to ensure that its parameter
61
+ /// meets the conditions set in its documentation.
62
+ ///
63
+ /// - Parameter changes: a collection of `CollectionDifference.Change`
64
+ /// instances intended to represent a valid state transition for
65
+ /// `CollectionDifference`.
66
+ ///
67
+ /// - Returns: whether the parameter meets the following criteria:
68
+ ///
69
+ /// 1. All insertion offsets are unique
70
+ /// 2. All removal offsets are unique
71
+ /// 3. All associations between insertions and removals are symmetric
72
+ ///
73
+ /// Complexity: O(`changes.count`)
62
74
private static func validateChanges< C> ( _ changes : C ) -> Bool where C: Collection , C. Element == Change {
63
75
if changes. count == 0 { return true }
64
76
@@ -105,11 +117,11 @@ public struct CollectionDifference<ChangeElement> {
105
117
/// states, this initializer will fail unless its parameter meets to the
106
118
/// following requirements:
107
119
///
108
- /// 1) All insertion offsets are unique
109
- /// 2) All removal offsets are unique
110
- /// 3) All offset associations between insertions and removals are symmetric
120
+ /// 1. All insertion offsets are unique
121
+ /// 2. All removal offsets are unique
122
+ /// 3. All associations between insertions and removals are symmetric
111
123
///
112
- /// - Parameter changes : A collection of changes that represent a transition
124
+ /// - Parameter c : A collection of changes that represent a transition
113
125
/// between two states.
114
126
///
115
127
/// - Complexity: O(*n* * log(*n*)), where *n* is the length of the
@@ -122,9 +134,18 @@ public struct CollectionDifference<ChangeElement> {
122
134
self . init ( validatedChanges: c)
123
135
}
124
136
125
- // Internal initializer for use by algorithms that cannot produce invalid
126
- // collections of changes. These include the Myers' diff algorithm and
127
- // the move inferencer.
137
+ /// Internal initializer for use by algorithms that cannot produce invalid
138
+ /// collections of changes. These include the Myers' diff algorithm and
139
+ /// the move inferencer.
140
+ ///
141
+ /// If parameter validity cannot be guaranteed by the caller then
142
+ /// `CollectionDifference.init?(_:)` should be used instead.
143
+ ///
144
+ /// - Parameter c: A valid collection of changes that represent a transition
145
+ /// between two states.
146
+ ///
147
+ /// - Complexity: O(*n* * log(*n*)), where *n* is the length of the
148
+ /// parameter.
128
149
init < C> ( validatedChanges c: C ) where C: Collection , C. Element == Change {
129
150
let changes = c. sorted { ( a, b) -> Bool in
130
151
switch ( a, b) {
0 commit comments