Skip to content

Commit

Permalink
Merge pull request #345 from gonini/migration
Browse files Browse the repository at this point in the history
Update Minimum Spanning Tree (Unweighted Graph) to Swift 3 syntax
  • Loading branch information
vincentngo committed Jan 4, 2017
2 parents 82f5750 + 017351f commit 11566eb
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Node>()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -27,15 +27,15 @@ 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!
}

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

for node in nodes {
duplicated.addNode(node.label)
_ = duplicated.addNode(node.label)
}

for node in nodes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }!)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public struct Queue<T> {
return array.count
}

public mutating func enqueue(element: T) {
public mutating func enqueue(_ element: T) {
array.append(element)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<Node>()
Expand Down
12 changes: 6 additions & 6 deletions Minimum Spanning Tree (Unweighted)/Tests/Graph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }!)
}
}

Expand All @@ -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)
}
Expand All @@ -78,15 +78,15 @@ 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!
}

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

for node in nodes {
duplicated.addNode(node.label)
_ = duplicated.addNode(node.label)
}

for node in nodes {
Expand Down
2 changes: 1 addition & 1 deletion Minimum Spanning Tree (Unweighted)/Tests/Queue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public struct Queue<T> {
return array.count
}

public mutating func enqueue(element: T) {
public mutating func enqueue(_ element: T) {
array.append(element)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
TargetAttributes = {
7B2BBC7F1C779D720067B71D = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0820;
};
};
};
Expand Down Expand Up @@ -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;
};
Expand All @@ -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;
};
Expand Down

0 comments on commit 11566eb

Please sign in to comment.