Skip to content

Commit 4552291

Browse files
committed
Header docs for internal methods validateChanges(_:) and init(validatedChanges:)
1 parent b7f36c3 commit 4552291

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

stdlib/public/core/CollectionDifference.swift

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,20 @@ public struct CollectionDifference<ChangeElement> {
5757
}
5858
}
5959

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`)
6274
private static func validateChanges<C>(_ changes : C) -> Bool where C:Collection, C.Element == Change {
6375
if changes.count == 0 { return true }
6476

@@ -105,11 +117,11 @@ public struct CollectionDifference<ChangeElement> {
105117
/// states, this initializer will fail unless its parameter meets to the
106118
/// following requirements:
107119
///
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
111123
///
112-
/// - Parameter changes: A collection of changes that represent a transition
124+
/// - Parameter c: A collection of changes that represent a transition
113125
/// between two states.
114126
///
115127
/// - Complexity: O(*n* * log(*n*)), where *n* is the length of the
@@ -122,9 +134,18 @@ public struct CollectionDifference<ChangeElement> {
122134
self.init(validatedChanges: c)
123135
}
124136

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.
128149
init<C>(validatedChanges c: C) where C:Collection, C.Element == Change {
129150
let changes = c.sorted { (a, b) -> Bool in
130151
switch (a, b) {

0 commit comments

Comments
 (0)