Skip to content

Commit 613a420

Browse files
author
ph1ps
committed
Swiftlint autocorrect
1 parent 83745f2 commit 613a420

File tree

70 files changed

+77
-243
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+77
-243
lines changed

AVL Tree/AVLTree.playground/Sources/AVLTree.swift

+2-3
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,11 @@ extension AVLTree {
341341
}
342342
} else {
343343
// Handle stem cases
344-
if let replacement = node.leftChild?.maximum() , replacement !== node {
344+
if let replacement = node.leftChild?.maximum(), replacement !== node {
345345
node.key = replacement.key
346346
node.payload = replacement.payload
347347
delete(node: replacement)
348-
} else if let replacement = node.rightChild?.minimum() , replacement !== node {
348+
} else if let replacement = node.rightChild?.minimum(), replacement !== node {
349349
node.key = replacement.key
350350
node.payload = replacement.payload
351351
delete(node: replacement)
@@ -354,7 +354,6 @@ extension AVLTree {
354354
}
355355
}
356356

357-
358357
// MARK: - Debugging
359358

360359
extension TreeNode: CustomDebugStringConvertible {

AVL Tree/AVLTree.swift

+2-3
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,11 @@ extension AVLTree {
341341
}
342342
} else {
343343
// Handle stem cases
344-
if let replacement = node.leftChild?.maximum() , replacement !== node {
344+
if let replacement = node.leftChild?.maximum(), replacement !== node {
345345
node.key = replacement.key
346346
node.payload = replacement.payload
347347
delete(node: replacement)
348-
} else if let replacement = node.rightChild?.minimum() , replacement !== node {
348+
} else if let replacement = node.rightChild?.minimum(), replacement !== node {
349349
node.key = replacement.key
350350
node.payload = replacement.payload
351351
delete(node: replacement)
@@ -354,7 +354,6 @@ extension AVLTree {
354354
}
355355
}
356356

357-
358357
// MARK: - Debugging
359358

360359
extension TreeNode: CustomDebugStringConvertible {

AVL Tree/Tests/TreeNodeTests.swift

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class TreeNodeTests: XCTestCase {
2727
super.tearDown()
2828
}
2929

30-
3130
func testSingleNodeCreationNOPayload() {
3231
let treeNode = TreeNode<String, String>(key: "Building")
3332
XCTAssertNil(treeNode.payload, "Payload for this case should be nil")

All-Pairs Shortest Paths/APSP/APSP/Helpers.swift

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import Foundation
99

10-
1110
/**
1211
Print a matrix, optionally specifying only the cells to display with the triplet (i, j, k) -> matrix[i][j], matrix[i][k], matrix[k][j]
1312
*/

Array2D/Array2D.playground/Contents.swift

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public struct Array2D<T> {
2828
}
2929
}
3030

31-
3231
// initialization
3332
var matrix = Array2D(columns: 3, rows: 5, initialValue: 0)
3433

Binary Tree/BinaryTree.playground/Contents.swift

-4
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ extension BinaryTree: CustomStringConvertible {
2525
}
2626
}
2727

28-
29-
3028
// leaf nodes
3129
let node5 = BinaryTree.node(.empty, "5", .empty)
3230
let nodeA = BinaryTree.node(.empty, "a", .empty)
@@ -50,8 +48,6 @@ let tree = BinaryTree.node(timesLeft, "+", timesRight)
5048
print(tree)
5149
tree.count // 12
5250

53-
54-
5551
extension BinaryTree {
5652
public func traverseInOrder(process: (T) -> Void) {
5753
if case let .node(left, value, right) = self {

Bit Set/BitSet.playground/Contents.swift

-9
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ print(bits)
2929

3030
print("")
3131

32-
33-
34-
3532
// Bitwise operations
3633

3734
var a = BitSet(size: 4)
@@ -69,9 +66,6 @@ print(~c) // 0101110000000000000000000000000000000000000000000000000000000000
6966
(~b).cardinality // 5
7067
(~c).cardinality // 4
7168

72-
73-
74-
7569
var z = BitSet(size: 66)
7670
z.all0() // true
7771
z.all1() // false
@@ -93,8 +87,5 @@ z.all1() // true
9387
z[65] = false
9488
z.all1() // false
9589

96-
97-
98-
9990
//var bigBits = BitSet(size: 10000)
10091
//print(bigBits)

Bloom Filter/BloomFilter.playground/Contents.swift

-4
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ public class BloomFilter<T> {
4747
}
4848
}
4949

50-
51-
5250
/* Two hash functions, adapted from http://www.cse.yorku.ca/~oz/hash.html */
5351

5452
func djb2(x: String) -> Int {
@@ -67,8 +65,6 @@ func sdbm(x: String) -> Int {
6765
return Int(hash)
6866
}
6967

70-
71-
7268
/* A simple test */
7369

7470
let bloom = BloomFilter<String>(size: 17, hashFunctions: [djb2, sdbm])

Bloom Filter/Tests/BloomFilterTests.swift

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ func sdbm(_ x: String) -> Int {
2323
return Int(hash)
2424
}
2525

26-
2726
class BloomFilterTests: XCTestCase {
2827

2928
func testSingleHashFunction() {

Bounded Priority Queue/BoundedPriorityQueue.playground/Contents.swift

-6
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ func < (m1: Message, m2: Message) -> Bool {
1515
return m1.priority < m2.priority
1616
}
1717

18-
19-
2018
let queue = BoundedPriorityQueue<Message>(maxElements: 5)
2119
queue.count
2220

@@ -48,8 +46,6 @@ print(queue)
4846
// At this point, the queue is:
4947
// <world:150, swift:110, hello:100, there:99, is:30, >
5048

51-
52-
5349
// Try to insert an item with a really low priority. This should not get added.
5450
queue.enqueue(Message(name: "very", priority: -1))
5551
queue.count // 5
@@ -70,8 +66,6 @@ queue.count
7066
queue.peek()
7167
print(queue)
7268

73-
74-
7569
// Test dequeuing
7670
queue.dequeue()
7771
queue.count

Breadth-First Search/BreadthFirstSearch.playground/Pages/Simple example.xcplaygroundpage/Contents.swift

-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ func breadthFirstSearch(_ graph: Graph, source: Node) -> [String] {
1919
return nodesExplored
2020
}
2121

22-
23-
2422
let graph = Graph()
2523

2624
let nodeA = graph.addNode("a")
@@ -42,6 +40,5 @@ graph.addEdge(nodeE, neighbor: nodeH)
4240
graph.addEdge(nodeE, neighbor: nodeF)
4341
graph.addEdge(nodeF, neighbor: nodeG)
4442

45-
4643
let nodesExplored = breadthFirstSearch(graph, source: nodeA)
4744
print(nodesExplored)

Brute-Force String Search/BruteForceStringSearch.playground/Contents.swift

-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ extension String {
2222
}
2323
}
2424

25-
26-
2725
// A few simple tests
2826

2927
let s = "Hello, World"

Bucket Sort/BucketSort.playground/Sources/BucketSort.swift

-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import Foundation
2626
// MARK: Main algorithm
2727
//////////////////////////////////////
2828

29-
3029
public func bucketSort<T: Sortable>(elements: [T], distributor: Distributor, sorter: Sorter, buckets: inout [Bucket<T>]) -> [T] {
3130
for elem in elements {
3231
distributor.distribute(element: elem, buckets: &buckets)
@@ -45,7 +44,6 @@ public func bucketSort<T: Sortable>(elements: [T], distributor: Distributor, sor
4544
// MARK: Distributor
4645
//////////////////////////////////////
4746

48-
4947
public protocol Distributor {
5048
func distribute<T: Sortable>(element: T, buckets: inout [Bucket<T>])
5149
}

Bucket Sort/BucketSort.swift

-3
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,10 @@ fileprivate func >= <T: Comparable>(lhs: T?, rhs: T?) -> Bool {
4545
}
4646
}
4747

48-
4948
//////////////////////////////////////
5049
// MARK: Main algorithm
5150
//////////////////////////////////////
5251

53-
5452
/**
5553
Performs bucket sort algorithm on the given input elements.
5654
[Bucket Sort Algorithm Reference](https://en.wikipedia.org/wiki/Bucket_sort)
@@ -96,7 +94,6 @@ private func enoughSpaceInBuckets<T: Sortable>(_ buckets: [Bucket<T>], elements:
9694
// MARK: Distributor
9795
//////////////////////////////////////
9896

99-
10097
public protocol Distributor {
10198
func distribute<T: Sortable>(_ element: T, buckets: inout [Bucket<T>])
10299
}

Bucket Sort/Tests/Tests.swift

-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ class TestTests: XCTestCase {
8686
}
8787
}
8888

89-
9089
//////////////////////////////////////
9190
// MARK: Extensions
9291
//////////////////////////////////////

Combinatorics/Combinatorics.playground/Contents.swift

-12
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ func factorial(_ n: Int) -> Int {
1414
factorial(5)
1515
factorial(20)
1616

17-
18-
1917
/*
2018
Calculates P(n, k), the number of permutations of n distinct symbols
2119
in groups of size k.
@@ -34,8 +32,6 @@ permutations(5, 3)
3432
permutations(50, 6)
3533
permutations(9, 4)
3634

37-
38-
3935
/*
4036
Prints out all the permutations of the given array.
4137
Original algorithm by Niklaus Wirth.
@@ -63,8 +59,6 @@ let xyz = [ "x", "y", "z" ]
6359
print("\nPermutations of \(xyz):")
6460
permuteWirth(xyz, 2)
6561

66-
67-
6862
/*
6963
Prints out all the permutations of an n-element collection.
7064

@@ -97,8 +91,6 @@ let numbers = [0, 0, 0, 0] // must be all zeros
9791
var pos = -1
9892
permuteSedgewick(numbers, 0, &pos)
9993

100-
101-
10294
/*
10395
Calculates C(n, k), or "n-choose-k", i.e. how many different selections
10496
of size k out of a total number of distinct elements (n) you can make.
@@ -115,8 +107,6 @@ for i in 1...20 {
115107
print("\(20)-choose-\(i) = \(combinations(20, choose: i))")
116108
}
117109

118-
119-
120110
/*
121111
Calculates C(n, k), or "n-choose-k", i.e. the number of ways to choose
122112
k things out of n possibilities.
@@ -134,8 +124,6 @@ func quickBinomialCoefficient(_ n: Int, choose k: Int) -> Int {
134124
quickBinomialCoefficient(8, choose: 2)
135125
quickBinomialCoefficient(30, choose: 15)
136126

137-
138-
139127
/* Supporting code because Swift doesn't have a built-in 2D array. */
140128
struct Array2D<T> {
141129
let columns: Int

Convex Hull/Convex Hull/AppDelegate.swift

-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1313

1414
var window: UIWindow?
1515

16-
1716
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
1817

1918
let screenBounds = UIScreen.main.bounds
@@ -52,5 +51,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
5251
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
5352
}
5453

55-
5654
}

Count Occurrences/CountOccurrences.playground/Contents.swift

-2
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,11 @@ func countOccurrencesOfKey(_ key: Int, inArray a: [Int]) -> Int {
3232
return rightBoundary() - leftBoundary()
3333
}
3434

35-
3635
// Simple test
3736

3837
let a = [ 0, 1, 1, 3, 3, 3, 3, 6, 8, 10, 11, 11 ]
3938
countOccurrencesOfKey(3, inArray: a)
4039

41-
4240
// Test with arrays of random size and contents (see debug output)
4341

4442
import Foundation

Counting Sort/CountingSort.playground/Contents.swift

-1
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,4 @@ func countingSort(array: [Int]) throws -> [Int] {
3737
return sortedArray
3838
}
3939

40-
4140
try countingSort(array: [10, 9, 8, 7, 1, 2, 7, 3])

Depth-First Search/DepthFirstSearch.playground/Pages/Simple Example.xcplaygroundpage/Contents.swift

-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ func depthFirstSearch(_ graph: Graph, source: Node) -> [String] {
1010
return nodesExplored
1111
}
1212

13-
14-
1513
let graph = Graph()
1614

1715
let nodeA = graph.addNode("a")

DiningPhilosophers/Sources/main.swift

-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//
77
//
88

9-
109
import Dispatch
1110

1211
let numberOfPhilosophers = 4
@@ -41,7 +40,6 @@ struct ForkPair {
4140
}
4241
}
4342

44-
4543
struct Philosophers {
4644
let forkPair: ForkPair
4745
let philosopherIndex: Int
@@ -75,7 +73,6 @@ struct Philosophers {
7573
}
7674
}
7775

78-
7976
// Layout of the table (P = philosopher, f = fork) for 4 Philosophers
8077
// P0
8178
// f3 f0
@@ -99,6 +96,5 @@ for semaphore in ForkPair.forksSemaphore {
9996
semaphore.signal()
10097
}
10198

102-
10399
//Wait forever
104100
globalSem.wait()

Graph/Graph/AdjacencyListGraph.swift

-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
import Foundation
99

10-
11-
1210
private class EdgeList<T> where T: Equatable, T: Hashable {
1311

1412
var vertex: Vertex<T>
@@ -90,7 +88,6 @@ open class AdjacencyListGraph<T>: AbstractGraph<T> where T: Equatable, T: Hashab
9088
addDirectedEdge(vertices.1, to: vertices.0, withWeight: weight)
9189
}
9290

93-
9491
open override func weightFrom(_ sourceVertex: Vertex<T>, to destinationVertex: Vertex<T>) -> Double? {
9592
guard let edges = adjacencyList[sourceVertex.index].edges else {
9693
return nil

Knuth-Morris-Pratt/KnuthMorrisPratt.playground/Contents.swift

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//: Playground - noun: a place where people can play
22

3-
43
func ZetaAlgorithm(ptnr: String) -> [Int]? {
54

65
let pattern = Array(ptnr.characters)

0 commit comments

Comments
 (0)