Skip to content

Commit

Permalink
Swiftlint autocorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
ph1ps committed May 25, 2017
1 parent 83745f2 commit 613a420
Show file tree
Hide file tree
Showing 70 changed files with 77 additions and 243 deletions.
5 changes: 2 additions & 3 deletions AVL Tree/AVLTree.playground/Sources/AVLTree.swift
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,11 @@ extension AVLTree {
}
} else {
// Handle stem cases
if let replacement = node.leftChild?.maximum() , replacement !== node {
if let replacement = node.leftChild?.maximum(), replacement !== node {
node.key = replacement.key
node.payload = replacement.payload
delete(node: replacement)
} else if let replacement = node.rightChild?.minimum() , replacement !== node {
} else if let replacement = node.rightChild?.minimum(), replacement !== node {
node.key = replacement.key
node.payload = replacement.payload
delete(node: replacement)
Expand All @@ -354,7 +354,6 @@ extension AVLTree {
}
}


// MARK: - Debugging

extension TreeNode: CustomDebugStringConvertible {
Expand Down
5 changes: 2 additions & 3 deletions AVL Tree/AVLTree.swift
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,11 @@ extension AVLTree {
}
} else {
// Handle stem cases
if let replacement = node.leftChild?.maximum() , replacement !== node {
if let replacement = node.leftChild?.maximum(), replacement !== node {
node.key = replacement.key
node.payload = replacement.payload
delete(node: replacement)
} else if let replacement = node.rightChild?.minimum() , replacement !== node {
} else if let replacement = node.rightChild?.minimum(), replacement !== node {
node.key = replacement.key
node.payload = replacement.payload
delete(node: replacement)
Expand All @@ -354,7 +354,6 @@ extension AVLTree {
}
}


// MARK: - Debugging

extension TreeNode: CustomDebugStringConvertible {
Expand Down
1 change: 0 additions & 1 deletion AVL Tree/Tests/TreeNodeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class TreeNodeTests: XCTestCase {
super.tearDown()
}


func testSingleNodeCreationNOPayload() {
let treeNode = TreeNode<String, String>(key: "Building")
XCTAssertNil(treeNode.payload, "Payload for this case should be nil")
Expand Down
1 change: 0 additions & 1 deletion All-Pairs Shortest Paths/APSP/APSP/Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import Foundation


/**
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]
*/
Expand Down
1 change: 0 additions & 1 deletion Array2D/Array2D.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public struct Array2D<T> {
}
}


// initialization
var matrix = Array2D(columns: 3, rows: 5, initialValue: 0)

Expand Down
4 changes: 0 additions & 4 deletions Binary Tree/BinaryTree.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ extension BinaryTree: CustomStringConvertible {
}
}



// leaf nodes
let node5 = BinaryTree.node(.empty, "5", .empty)
let nodeA = BinaryTree.node(.empty, "a", .empty)
Expand All @@ -50,8 +48,6 @@ let tree = BinaryTree.node(timesLeft, "+", timesRight)
print(tree)
tree.count // 12



extension BinaryTree {
public func traverseInOrder(process: (T) -> Void) {
if case let .node(left, value, right) = self {
Expand Down
9 changes: 0 additions & 9 deletions Bit Set/BitSet.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ print(bits)

print("")




// Bitwise operations

var a = BitSet(size: 4)
Expand Down Expand Up @@ -69,9 +66,6 @@ print(~c) // 0101110000000000000000000000000000000000000000000000000000000000
(~b).cardinality // 5
(~c).cardinality // 4




var z = BitSet(size: 66)
z.all0() // true
z.all1() // false
Expand All @@ -93,8 +87,5 @@ z.all1() // true
z[65] = false
z.all1() // false




//var bigBits = BitSet(size: 10000)
//print(bigBits)
4 changes: 0 additions & 4 deletions Bloom Filter/BloomFilter.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ public class BloomFilter<T> {
}
}



/* Two hash functions, adapted from http://www.cse.yorku.ca/~oz/hash.html */

func djb2(x: String) -> Int {
Expand All @@ -67,8 +65,6 @@ func sdbm(x: String) -> Int {
return Int(hash)
}



/* A simple test */

let bloom = BloomFilter<String>(size: 17, hashFunctions: [djb2, sdbm])
Expand Down
1 change: 0 additions & 1 deletion Bloom Filter/Tests/BloomFilterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func sdbm(_ x: String) -> Int {
return Int(hash)
}


class BloomFilterTests: XCTestCase {

func testSingleHashFunction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ func < (m1: Message, m2: Message) -> Bool {
return m1.priority < m2.priority
}



let queue = BoundedPriorityQueue<Message>(maxElements: 5)
queue.count

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



// Try to insert an item with a really low priority. This should not get added.
queue.enqueue(Message(name: "very", priority: -1))
queue.count // 5
Expand All @@ -70,8 +66,6 @@ queue.count
queue.peek()
print(queue)



// Test dequeuing
queue.dequeue()
queue.count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ func breadthFirstSearch(_ graph: Graph, source: Node) -> [String] {
return nodesExplored
}



let graph = Graph()

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


let nodesExplored = breadthFirstSearch(graph, source: nodeA)
print(nodesExplored)
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ extension String {
}
}



// A few simple tests

let s = "Hello, World"
Expand Down
2 changes: 0 additions & 2 deletions Bucket Sort/BucketSort.playground/Sources/BucketSort.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import Foundation
// MARK: Main algorithm
//////////////////////////////////////


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


public protocol Distributor {
func distribute<T: Sortable>(element: T, buckets: inout [Bucket<T>])
}
Expand Down
3 changes: 0 additions & 3 deletions Bucket Sort/BucketSort.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@ fileprivate func >= <T: Comparable>(lhs: T?, rhs: T?) -> Bool {
}
}


//////////////////////////////////////
// MARK: Main algorithm
//////////////////////////////////////


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


public protocol Distributor {
func distribute<T: Sortable>(_ element: T, buckets: inout [Bucket<T>])
}
Expand Down
1 change: 0 additions & 1 deletion Bucket Sort/Tests/Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ class TestTests: XCTestCase {
}
}


//////////////////////////////////////
// MARK: Extensions
//////////////////////////////////////
Expand Down
12 changes: 0 additions & 12 deletions Combinatorics/Combinatorics.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ func factorial(_ n: Int) -> Int {
factorial(5)
factorial(20)



/*
Calculates P(n, k), the number of permutations of n distinct symbols
in groups of size k.
Expand All @@ -34,8 +32,6 @@ permutations(5, 3)
permutations(50, 6)
permutations(9, 4)



/*
Prints out all the permutations of the given array.
Original algorithm by Niklaus Wirth.
Expand Down Expand Up @@ -63,8 +59,6 @@ let xyz = [ "x", "y", "z" ]
print("\nPermutations of \(xyz):")
permuteWirth(xyz, 2)



/*
Prints out all the permutations of an n-element collection.
Expand Down Expand Up @@ -97,8 +91,6 @@ let numbers = [0, 0, 0, 0] // must be all zeros
var pos = -1
permuteSedgewick(numbers, 0, &pos)



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



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



/* Supporting code because Swift doesn't have a built-in 2D array. */
struct Array2D<T> {
let columns: Int
Expand Down
2 changes: 0 additions & 2 deletions Convex Hull/Convex Hull/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


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

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


}
2 changes: 0 additions & 2 deletions Count Occurrences/CountOccurrences.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ func countOccurrencesOfKey(_ key: Int, inArray a: [Int]) -> Int {
return rightBoundary() - leftBoundary()
}


// Simple test

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


// Test with arrays of random size and contents (see debug output)

import Foundation
Expand Down
1 change: 0 additions & 1 deletion Counting Sort/CountingSort.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,4 @@ func countingSort(array: [Int]) throws -> [Int] {
return sortedArray
}


try countingSort(array: [10, 9, 8, 7, 1, 2, 7, 3])
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ func depthFirstSearch(_ graph: Graph, source: Node) -> [String] {
return nodesExplored
}



let graph = Graph()

let nodeA = graph.addNode("a")
Expand Down
4 changes: 0 additions & 4 deletions DiningPhilosophers/Sources/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//
//


import Dispatch

let numberOfPhilosophers = 4
Expand Down Expand Up @@ -41,7 +40,6 @@ struct ForkPair {
}
}


struct Philosophers {
let forkPair: ForkPair
let philosopherIndex: Int
Expand Down Expand Up @@ -75,7 +73,6 @@ struct Philosophers {
}
}


// Layout of the table (P = philosopher, f = fork) for 4 Philosophers
// P0
// f3 f0
Expand All @@ -99,6 +96,5 @@ for semaphore in ForkPair.forksSemaphore {
semaphore.signal()
}


//Wait forever
globalSem.wait()
3 changes: 0 additions & 3 deletions Graph/Graph/AdjacencyListGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import Foundation



private class EdgeList<T> where T: Equatable, T: Hashable {

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


open override func weightFrom(_ sourceVertex: Vertex<T>, to destinationVertex: Vertex<T>) -> Double? {
guard let edges = adjacencyList[sourceVertex.index].edges else {
return nil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//: Playground - noun: a place where people can play


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

let pattern = Array(ptnr.characters)
Expand Down
Loading

0 comments on commit 613a420

Please sign in to comment.