Skip to content

Commit e9205f1

Browse files
stephencelisactions-user
authored andcommitted
Run swift-format
1 parent 5b23c62 commit e9205f1

File tree

2 files changed

+75
-75
lines changed

2 files changed

+75
-75
lines changed

Sources/CustomDump/Internal/CollectionDifference.swift

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -33,33 +33,27 @@ struct CollectionDifference<ChangeElement> {
3333

3434
// Internal common field accessors
3535
internal var _offset: Int {
36-
get {
37-
switch self {
38-
case .insert(offset: let o, element: _, associatedWith: _):
39-
return o
40-
case .remove(offset: let o, element: _, associatedWith: _):
41-
return o
42-
}
36+
switch self {
37+
case .insert(offset: let o, element: _, associatedWith: _):
38+
return o
39+
case .remove(offset: let o, element: _, associatedWith: _):
40+
return o
4341
}
4442
}
4543
internal var _element: ChangeElement {
46-
get {
47-
switch self {
48-
case .insert(offset: _, element: let e, associatedWith: _):
49-
return e
50-
case .remove(offset: _, element: let e, associatedWith: _):
51-
return e
52-
}
44+
switch self {
45+
case .insert(offset: _, element: let e, associatedWith: _):
46+
return e
47+
case .remove(offset: _, element: let e, associatedWith: _):
48+
return e
5349
}
5450
}
5551
internal var _associatedOffset: Int? {
56-
get {
57-
switch self {
58-
case .insert(offset: _, element: _, associatedWith: let o):
59-
return o
60-
case .remove(offset: _, element: _, associatedWith: let o):
61-
return o
62-
}
52+
switch self {
53+
case .insert(offset: _, element: _, associatedWith: let o):
54+
return o
55+
case .remove(offset: _, element: _, associatedWith: let o):
56+
return o
6357
}
6458
}
6559
}
@@ -162,12 +156,12 @@ struct CollectionDifference<ChangeElement> {
162156
///
163157
/// Complexity: O(`changes.count`)
164158
private static func _validateChanges<Changes: Collection>(
165-
_ changes : Changes
159+
_ changes: Changes
166160
) -> Bool where Changes.Element == Change {
167161
if changes.isEmpty { return true }
168162

169-
var insertAssocToOffset = Dictionary<Int,Int>()
170-
var removeOffsetToAssoc = Dictionary<Int,Int>()
163+
var insertAssocToOffset = [Int: Int]()
164+
var removeOffsetToAssoc = [Int: Int]()
171165
var insertOffset = Set<Int>()
172166
var removeOffset = Set<Int>()
173167

@@ -201,14 +195,15 @@ struct CollectionDifference<ChangeElement> {
201195
}
202196

203197
func inverse() -> Self {
204-
return CollectionDifference(_validatedChanges: self.map { c in
205-
switch c {
198+
return CollectionDifference(
199+
_validatedChanges: self.map { c in
200+
switch c {
206201
case .remove(let o, let e, let a):
207202
return .insert(offset: o, element: e, associatedWith: a)
208203
case .insert(let o, let e, let a):
209204
return .remove(offset: o, element: e, associatedWith: a)
210-
}
211-
})
205+
}
206+
})
212207
}
213208
}
214209

@@ -321,8 +316,9 @@ extension CollectionDifference where ChangeElement: Hashable {
321316
///
322317
/// - Complexity: O(*n*) where *n* is the number of collection differences.
323318
func inferringMoves() -> CollectionDifference<ChangeElement> {
324-
let uniqueRemovals: [ChangeElement:Int?] = {
325-
var result = [ChangeElement:Int?](minimumCapacity: Swift.min(removals.count, insertions.count))
319+
let uniqueRemovals: [ChangeElement: Int?] = {
320+
var result = [ChangeElement: Int?](
321+
minimumCapacity: Swift.min(removals.count, insertions.count))
326322
for removal in removals {
327323
let element = removal._element
328324
if result[element] != .none {
@@ -334,8 +330,9 @@ extension CollectionDifference where ChangeElement: Hashable {
334330
return result.filter { (_, v) -> Bool in v != .none }
335331
}()
336332

337-
let uniqueInsertions: [ChangeElement:Int?] = {
338-
var result = [ChangeElement:Int?](minimumCapacity: Swift.min(removals.count, insertions.count))
333+
let uniqueInsertions: [ChangeElement: Int?] = {
334+
var result = [ChangeElement: Int?](
335+
minimumCapacity: Swift.min(removals.count, insertions.count))
339336
for insertion in insertions {
340337
let element = insertion._element
341338
if result[element] != .none {
@@ -347,25 +344,26 @@ extension CollectionDifference where ChangeElement: Hashable {
347344
return result.filter { (_, v) -> Bool in v != .none }
348345
}()
349346

350-
return CollectionDifference(_validatedChanges: map({ (change: Change) -> Change in
351-
switch change {
352-
case .remove(offset: let offset, element: let element, associatedWith: _):
353-
if uniqueRemovals[element] == nil {
354-
return change
355-
}
356-
if let assoc = uniqueInsertions[element] {
357-
return .remove(offset: offset, element: element, associatedWith: assoc)
358-
}
359-
case .insert(offset: let offset, element: let element, associatedWith: _):
360-
if uniqueInsertions[element] == nil {
361-
return change
362-
}
363-
if let assoc = uniqueRemovals[element] {
364-
return .insert(offset: offset, element: element, associatedWith: assoc)
347+
return CollectionDifference(
348+
_validatedChanges: map({ (change: Change) -> Change in
349+
switch change {
350+
case .remove(let offset, let element, associatedWith: _):
351+
if uniqueRemovals[element] == nil {
352+
return change
353+
}
354+
if let assoc = uniqueInsertions[element] {
355+
return .remove(offset: offset, element: element, associatedWith: assoc)
356+
}
357+
case .insert(let offset, let element, associatedWith: _):
358+
if uniqueInsertions[element] == nil {
359+
return change
360+
}
361+
if let assoc = uniqueRemovals[element] {
362+
return .insert(offset: offset, element: element, associatedWith: assoc)
363+
}
365364
}
366-
}
367-
return change
368-
}))
365+
return change
366+
}))
369367
}
370368
}
371369

Sources/CustomDump/Internal/Diffing.swift

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ extension CollectionDifference {
5353
}
5454

5555
// Error type allows the use of throw to unroll state on application failure
56-
private enum _ApplicationError : Error { case failed }
56+
private enum _ApplicationError: Error { case failed }
5757

5858
extension RangeReplaceableCollection {
5959
/// Applies the given difference to this collection.
@@ -88,17 +88,17 @@ extension RangeReplaceableCollection {
8888
var currentIndex = self.startIndex
8989
try difference._fastEnumeratedApply { change in
9090
switch change {
91-
case .remove(offset: let offset, element: _, associatedWith: _):
91+
case .remove(let offset, element: _, associatedWith: _):
9292
let origCount = offset - enumeratedOriginals
9393
try append(into: &result, contentsOf: self, from: &currentIndex, count: origCount)
9494
if currentIndex == self.endIndex {
9595
// Removing nonexistent element off the end of the collection
9696
throw _ApplicationError.failed
9797
}
98-
enumeratedOriginals += origCount + 1 // Removal consumes an original element
98+
enumeratedOriginals += origCount + 1 // Removal consumes an original element
9999
currentIndex = self.index(after: currentIndex)
100100
enumeratedRemoves += 1
101-
case .insert(offset: let offset, element: let element, associatedWith: _):
101+
case .insert(let offset, let element, associatedWith: _):
102102
let origCount = (offset + enumeratedRemoves - enumeratedInserts) - enumeratedOriginals
103103
try append(into: &result, contentsOf: self, from: &currentIndex, count: origCount)
104104
result.append(element)
@@ -185,15 +185,15 @@ extension BidirectionalCollection where Element: Equatable {
185185
private struct _V {
186186

187187
private var a: [Int]
188-
#if INTERNAL_CHECKS_ENABLED
189-
private let isOdd: Bool
190-
#endif
188+
#if INTERNAL_CHECKS_ENABLED
189+
private let isOdd: Bool
190+
#endif
191191

192192
init(maxIndex largest: Int) {
193-
#if INTERNAL_CHECKS_ENABLED
194-
_internalInvariant(largest >= 0)
195-
isOdd = largest % 2 == 1
196-
#endif
193+
#if INTERNAL_CHECKS_ENABLED
194+
_internalInvariant(largest >= 0)
195+
isOdd = largest % 2 == 1
196+
#endif
197197
a = [Int](repeating: 0, count: largest + 1)
198198
}
199199

@@ -206,33 +206,35 @@ private struct _V {
206206

207207
subscript(index: Int) -> Int {
208208
get {
209-
#if INTERNAL_CHECKS_ENABLED
210-
_internalInvariant(isOdd == (index % 2 != 0))
211-
#endif
209+
#if INTERNAL_CHECKS_ENABLED
210+
_internalInvariant(isOdd == (index % 2 != 0))
211+
#endif
212212
return a[_V.transform(index)]
213213
}
214214
set(newValue) {
215-
#if INTERNAL_CHECKS_ENABLED
216-
_internalInvariant(isOdd == (index % 2 != 0))
217-
#endif
215+
#if INTERNAL_CHECKS_ENABLED
216+
_internalInvariant(isOdd == (index % 2 != 0))
217+
#endif
218218
a[_V.transform(index)] = newValue
219219
}
220220
}
221221
}
222222

223-
private func _myers<C,D>(
223+
private func _myers<C, D>(
224224
from old: C, to new: D,
225225
using cmp: (C.Element, D.Element) -> Bool
226226
) -> CollectionDifference<C.Element>
227-
where
228-
C: BidirectionalCollection,
229-
D: BidirectionalCollection,
230-
C.Element == D.Element
227+
where
228+
C: BidirectionalCollection,
229+
D: BidirectionalCollection,
230+
C.Element == D.Element
231231
{
232232

233233
// Core implementation of the algorithm described at http://www.xmailserver.org/diff2.pdf
234234
// Variable names match those used in the paper as closely as possible
235-
func _descent(from a: UnsafeBufferPointer<C.Element>, to b: UnsafeBufferPointer<D.Element>) -> [_V] {
235+
func _descent(from a: UnsafeBufferPointer<C.Element>, to b: UnsafeBufferPointer<D.Element>)
236+
-> [_V]
237+
{
236238
let n = a.count
237239
let m = b.count
238240
let max = n + m
@@ -271,7 +273,7 @@ private func _myers<C,D>(
271273

272274
while x < n && y < m {
273275
if !cmp(a[x], b[y]) {
274-
break;
276+
break
275277
}
276278
x &+= 1
277279
y &+= 1
@@ -355,7 +357,7 @@ private func _myers<C,D>(
355357

356358
return _withContiguousStorage(for: old) { a in
357359
return _withContiguousStorage(for: new) { b in
358-
return CollectionDifference(_formChanges(from: a, to: b, using:_descent(from: a, to: b)))!
360+
return CollectionDifference(_formChanges(from: a, to: b, using: _descent(from: a, to: b)))!
359361
}
360362
}
361363
}

0 commit comments

Comments
 (0)