Skip to content

Commit 11566eb

Browse files
authored
Merge pull request kodecocodes#345 from gonini/migration
Update Minimum Spanning Tree (Unweighted Graph) to Swift 3 syntax
2 parents 82f5750 + 017351f commit 11566eb

File tree

10 files changed

+20
-23
lines changed

10 files changed

+20
-23
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ script:
2828
# - xcodebuild test -project ./K-Means/Tests/Tests.xcodeproj -scheme Tests
2929
# - xcodebuild test -project ./Linked\ List/Tests/Tests.xcodeproj -scheme Tests
3030
- xcodebuild test -project ./Longest\ Common\ Subsequence/Tests/Tests.xcodeproj -scheme Tests
31-
# - xcodebuild test -project ./Minimum\ Spanning\ Tree\ \(Unweighted\)/Tests/Tests.xcodeproj -scheme Tests
31+
- xcodebuild test -project ./Minimum\ Spanning\ Tree\ \(Unweighted\)/Tests/Tests.xcodeproj -scheme Tests
3232
# - xcodebuild test -project ./Priority\ Queue/Tests/Tests.xcodeproj -scheme Tests
3333
- xcodebuild test -project ./Queue/Tests/Tests.xcodeproj -scheme Tests
3434
# - xcodebuild test -project ./Quicksort/Tests/Tests.xcodeproj -scheme Tests

Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Pages/Minimum spanning tree example.xcplaygroundpage/Contents.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
func breadthFirstSearchMinimumSpanningTree(graph: Graph, source: Node) -> Graph {
1+
func breadthFirstSearchMinimumSpanningTree(_ graph: Graph, source: Node) -> Graph {
22
let minimumSpanningTree = graph.duplicate()
33

44
var queue = Queue<Node>()

Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Pages/Minimum spanning tree example.xcplaygroundpage/timeline.xctimeline

Lines changed: 0 additions & 6 deletions
This file was deleted.

Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Sources/Graph.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ public class Graph: CustomStringConvertible, Equatable {
55
self.nodes = []
66
}
77

8-
public func addNode(label: String) -> Node {
8+
public func addNode(_ label: String) -> Node {
99
let node = Node(label: label)
1010
nodes.append(node)
1111
return node
1212
}
1313

14-
public func addEdge(source: Node, neighbor: Node) {
14+
public func addEdge(_ source: Node, neighbor: Node) {
1515
let edge = Edge(neighbor: neighbor)
1616
source.neighbors.append(edge)
1717
}
@@ -27,15 +27,15 @@ public class Graph: CustomStringConvertible, Equatable {
2727
return description
2828
}
2929

30-
public func findNodeWithLabel(label: String) -> Node {
30+
public func findNodeWithLabel(_ label: String) -> Node {
3131
return nodes.filter { $0.label == label }.first!
3232
}
3333

3434
public func duplicate() -> Graph {
3535
let duplicated = Graph()
3636

3737
for node in nodes {
38-
duplicated.addNode(node.label)
38+
_ = duplicated.addNode(node.label)
3939
}
4040

4141
for node in nodes {

Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Sources/Node.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public class Node: CustomStringConvertible, Equatable {
2222
return distance != nil
2323
}
2424

25-
public func remove(edge: Edge) {
26-
neighbors.removeAtIndex(neighbors.indexOf { $0 === edge }!)
25+
public func remove(_ edge: Edge) {
26+
neighbors.remove(at: neighbors.index { $0 === edge }!)
2727
}
2828
}
2929

Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.playground/Sources/Queue.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public struct Queue<T> {
1313
return array.count
1414
}
1515

16-
public mutating func enqueue(element: T) {
16+
public mutating func enqueue(_ element: T) {
1717
array.append(element)
1818
}
1919

Minimum Spanning Tree (Unweighted)/MinimumSpanningTree.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
func breadthFirstSearchMinimumSpanningTree(graph: Graph, source: Node) -> Graph {
1+
func breadthFirstSearchMinimumSpanningTree(_ graph: Graph, source: Node) -> Graph {
22
let minimumSpanningTree = graph.duplicate()
33

44
var queue = Queue<Node>()

Minimum Spanning Tree (Unweighted)/Tests/Graph.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public class Node: CustomStringConvertible, Equatable {
3838
return distance != nil
3939
}
4040

41-
public func remove(edge: Edge) {
42-
neighbors.removeAtIndex(neighbors.indexOf { $0 === edge }!)
41+
public func remove(_ edge: Edge) {
42+
neighbors.remove(at: neighbors.index { $0 === edge }!)
4343
}
4444
}
4545

@@ -56,13 +56,13 @@ public class Graph: CustomStringConvertible, Equatable {
5656
self.nodes = []
5757
}
5858

59-
public func addNode(label: String) -> Node {
59+
public func addNode(_ label: String) -> Node {
6060
let node = Node(label: label)
6161
nodes.append(node)
6262
return node
6363
}
6464

65-
public func addEdge(source: Node, neighbor: Node) {
65+
public func addEdge(_ source: Node, neighbor: Node) {
6666
let edge = Edge(neighbor: neighbor)
6767
source.neighbors.append(edge)
6868
}
@@ -78,15 +78,15 @@ public class Graph: CustomStringConvertible, Equatable {
7878
return description
7979
}
8080

81-
public func findNodeWithLabel(label: String) -> Node {
81+
public func findNodeWithLabel(_ label: String) -> Node {
8282
return nodes.filter { $0.label == label }.first!
8383
}
8484

8585
public func duplicate() -> Graph {
8686
let duplicated = Graph()
8787

8888
for node in nodes {
89-
duplicated.addNode(node.label)
89+
_ = duplicated.addNode(node.label)
9090
}
9191

9292
for node in nodes {

Minimum Spanning Tree (Unweighted)/Tests/Queue.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public struct Queue<T> {
1313
return array.count
1414
}
1515

16-
public mutating func enqueue(element: T) {
16+
public mutating func enqueue(_ element: T) {
1717
array.append(element)
1818
}
1919

Minimum Spanning Tree (Unweighted)/Tests/Tests.xcodeproj/project.pbxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
TargetAttributes = {
9595
7B2BBC7F1C779D720067B71D = {
9696
CreatedOnToolsVersion = 7.2;
97+
LastSwiftMigration = 0820;
9798
};
9899
};
99100
};
@@ -230,6 +231,7 @@
230231
PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests;
231232
PRODUCT_NAME = "$(TARGET_NAME)";
232233
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
234+
SWIFT_VERSION = 3.0;
233235
};
234236
name = Debug;
235237
};
@@ -242,6 +244,7 @@
242244
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
243245
PRODUCT_BUNDLE_IDENTIFIER = swift.algorithm.club.Tests;
244246
PRODUCT_NAME = "$(TARGET_NAME)";
247+
SWIFT_VERSION = 3.0;
245248
};
246249
name = Release;
247250
};

0 commit comments

Comments
 (0)