From 947d4f8052bccdb6f8a104ab1d36892d8152d92e Mon Sep 17 00:00:00 2001 From: gonini Date: Wed, 4 Jan 2017 09:46:09 +0900 Subject: [PATCH 1/3] Update Minimum Spanning Tree (Unweighted Graph) to Swift 3 --- .../Contents.swift | 2 +- .../timeline.xctimeline | 6 ------ .../MinimumSpanningTree.playground/Sources/Graph.swift | 6 +++--- .../MinimumSpanningTree.playground/Sources/Node.swift | 4 ++-- .../MinimumSpanningTree.playground/Sources/Queue.swift | 2 +- .../MinimumSpanningTree.swift | 2 +- Minimum Spanning Tree (Unweighted)/Tests/Graph.swift | 10 +++++----- Minimum Spanning Tree (Unweighted)/Tests/Queue.swift | 2 +- .../Tests/Tests.xcodeproj/project.pbxproj | 3 +++ 9 files changed, 17 insertions(+), 20 deletions(-) delete mode 100644 Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Pages/Minimum spanning tree example.xcplaygroundpage/timeline.xctimeline diff --git a/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Pages/Minimum spanning tree example.xcplaygroundpage/Contents.swift b/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Pages/Minimum spanning tree example.xcplaygroundpage/Contents.swift index 088da1d11..86fe27df8 100644 --- a/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Pages/Minimum spanning tree example.xcplaygroundpage/Contents.swift +++ b/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Pages/Minimum spanning tree example.xcplaygroundpage/Contents.swift @@ -1,4 +1,4 @@ -func breadthFirstSearchMinimumSpanningTree(graph: Graph, source: Node) -> Graph { +func breadthFirstSearchMinimumSpanningTree(_ graph: Graph, source: Node) -> Graph { let minimumSpanningTree = graph.duplicate() var queue = Queue() diff --git a/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Pages/Minimum spanning tree example.xcplaygroundpage/timeline.xctimeline b/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Pages/Minimum spanning tree example.xcplaygroundpage/timeline.xctimeline deleted file mode 100644 index bf468afec..000000000 --- a/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Pages/Minimum spanning tree example.xcplaygroundpage/timeline.xctimeline +++ /dev/null @@ -1,6 +0,0 @@ - - - - - diff --git a/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Sources/Graph.swift b/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Sources/Graph.swift index 8cfb2a09c..8f02baf92 100644 --- a/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Sources/Graph.swift +++ b/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Sources/Graph.swift @@ -5,13 +5,13 @@ public class Graph: CustomStringConvertible, Equatable { self.nodes = [] } - public func addNode(label: String) -> Node { + public func addNode(_ label: String) -> Node { let node = Node(label: label) nodes.append(node) return node } - public func addEdge(source: Node, neighbor: Node) { + public func addEdge(_ source: Node, neighbor: Node) { let edge = Edge(neighbor: neighbor) source.neighbors.append(edge) } @@ -27,7 +27,7 @@ public class Graph: CustomStringConvertible, Equatable { return description } - public func findNodeWithLabel(label: String) -> Node { + public func findNodeWithLabel(_ label: String) -> Node { return nodes.filter { $0.label == label }.first! } diff --git a/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Sources/Node.swift b/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Sources/Node.swift index 37a3b3fdf..0aedb6ef9 100644 --- a/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Sources/Node.swift +++ b/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Sources/Node.swift @@ -22,8 +22,8 @@ public class Node: CustomStringConvertible, Equatable { return distance != nil } - public func remove(edge: Edge) { - neighbors.removeAtIndex(neighbors.indexOf { $0 === edge }!) + public func remove(_ edge: Edge) { + neighbors.remove(at: neighbors.index { $0 === edge }!) } } diff --git a/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Sources/Queue.swift b/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Sources/Queue.swift index bf462bbdd..3d98f801c 100644 --- a/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Sources/Queue.swift +++ b/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Sources/Queue.swift @@ -13,7 +13,7 @@ public struct Queue { return array.count } - public mutating func enqueue(element: T) { + public mutating func enqueue(_ element: T) { array.append(element) } diff --git a/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.swift b/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.swift index 92d370878..645a41999 100644 --- a/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.swift +++ b/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.swift @@ -1,4 +1,4 @@ -func breadthFirstSearchMinimumSpanningTree(graph: Graph, source: Node) -> Graph { +func breadthFirstSearchMinimumSpanningTree(_ graph: Graph, source: Node) -> Graph { let minimumSpanningTree = graph.duplicate() var queue = Queue() diff --git a/Minimum Spanning Tree (Unweighted)/Tests/Graph.swift b/Minimum Spanning Tree (Unweighted)/Tests/Graph.swift index ed71cab7c..2d4161245 100644 --- a/Minimum Spanning Tree (Unweighted)/Tests/Graph.swift +++ b/Minimum Spanning Tree (Unweighted)/Tests/Graph.swift @@ -38,8 +38,8 @@ public class Node: CustomStringConvertible, Equatable { return distance != nil } - public func remove(edge: Edge) { - neighbors.removeAtIndex(neighbors.indexOf { $0 === edge }!) + public func remove(_ edge: Edge) { + neighbors.remove(at: neighbors.index { $0 === edge }!) } } @@ -56,13 +56,13 @@ public class Graph: CustomStringConvertible, Equatable { self.nodes = [] } - public func addNode(label: String) -> Node { + public func addNode(_ label: String) -> Node { let node = Node(label: label) nodes.append(node) return node } - public func addEdge(source: Node, neighbor: Node) { + public func addEdge(_ source: Node, neighbor: Node) { let edge = Edge(neighbor: neighbor) source.neighbors.append(edge) } @@ -78,7 +78,7 @@ public class Graph: CustomStringConvertible, Equatable { return description } - public func findNodeWithLabel(label: String) -> Node { + public func findNodeWithLabel(_ label: String) -> Node { return nodes.filter { $0.label == label }.first! } diff --git a/Minimum Spanning Tree (Unweighted)/Tests/Queue.swift b/Minimum Spanning Tree (Unweighted)/Tests/Queue.swift index bf462bbdd..3d98f801c 100644 --- a/Minimum Spanning Tree (Unweighted)/Tests/Queue.swift +++ b/Minimum Spanning Tree (Unweighted)/Tests/Queue.swift @@ -13,7 +13,7 @@ public struct Queue { return array.count } - public mutating func enqueue(element: T) { + public mutating func enqueue(_ element: T) { array.append(element) } diff --git a/Minimum Spanning Tree (Unweighted)/Tests/Tests.xcodeproj/project.pbxproj b/Minimum Spanning Tree (Unweighted)/Tests/Tests.xcodeproj/project.pbxproj index 659c7e9f2..a066b7a71 100644 --- a/Minimum Spanning Tree (Unweighted)/Tests/Tests.xcodeproj/project.pbxproj +++ b/Minimum Spanning Tree (Unweighted)/Tests/Tests.xcodeproj/project.pbxproj @@ -94,6 +94,7 @@ TargetAttributes = { 7B2BBC7F1C779D720067B71D = { CreatedOnToolsVersion = 7.2; + LastSwiftMigration = 0820; }; }; }; @@ -230,6 +231,7 @@ PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -242,6 +244,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; From fc208c61f96838af6266980bd058f7141b3cac24 Mon Sep 17 00:00:00 2001 From: GongUi Date: Wed, 4 Jan 2017 09:48:04 +0900 Subject: [PATCH 2/3] Update .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4e2918431..4fbf215de 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,7 +28,7 @@ script: # - xcodebuild test -project ./K-Means/Tests/Tests.xcodeproj -scheme Tests # - xcodebuild test -project ./Linked\ List/Tests/Tests.xcodeproj -scheme Tests - xcodebuild test -project ./Longest\ Common\ Subsequence/Tests/Tests.xcodeproj -scheme Tests -# - xcodebuild test -project ./Minimum\ Spanning\ Tree\ \(Unweighted\)/Tests/Tests.xcodeproj -scheme Tests +- xcodebuild test -project ./Minimum\ Spanning\ Tree\ \(Unweighted\)/Tests/Tests.xcodeproj -scheme Tests # - xcodebuild test -project ./Priority\ Queue/Tests/Tests.xcodeproj -scheme Tests - xcodebuild test -project ./Queue/Tests/Tests.xcodeproj -scheme Tests # - xcodebuild test -project ./Quicksort/Tests/Tests.xcodeproj -scheme Tests From 017351f6bb67368ff273d73cba89e1ee42aa45f2 Mon Sep 17 00:00:00 2001 From: gonini Date: Thu, 5 Jan 2017 08:10:11 +0900 Subject: [PATCH 3/3] Warning correction for unused return function --- .../MinimumSpanningTree.playground/Sources/Graph.swift | 2 +- Minimum Spanning Tree (Unweighted)/Tests/Graph.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Sources/Graph.swift b/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Sources/Graph.swift index 8f02baf92..e2bb82677 100644 --- a/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Sources/Graph.swift +++ b/Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Sources/Graph.swift @@ -35,7 +35,7 @@ public class Graph: CustomStringConvertible, Equatable { let duplicated = Graph() for node in nodes { - duplicated.addNode(node.label) + _ = duplicated.addNode(node.label) } for node in nodes { diff --git a/Minimum Spanning Tree (Unweighted)/Tests/Graph.swift b/Minimum Spanning Tree (Unweighted)/Tests/Graph.swift index 2d4161245..c8cb77ac8 100644 --- a/Minimum Spanning Tree (Unweighted)/Tests/Graph.swift +++ b/Minimum Spanning Tree (Unweighted)/Tests/Graph.swift @@ -86,7 +86,7 @@ public class Graph: CustomStringConvertible, Equatable { let duplicated = Graph() for node in nodes { - duplicated.addNode(node.label) + _ = duplicated.addNode(node.label) } for node in nodes {