1
1
// MARK: - Edge
2
2
3
- public class Edge : Equatable {
4
- public var neighbor : Node
3
+ open class Edge : Equatable {
4
+ open var neighbor : Node
5
5
6
6
public init ( neighbor: Node ) {
7
7
self . neighbor = neighbor
@@ -15,31 +15,31 @@ public func == (lhs: Edge, rhs: Edge) -> Bool {
15
15
16
16
// MARK: - Node
17
17
18
- public class Node : CustomStringConvertible , Equatable {
19
- public var neighbors : [ Edge ]
18
+ open class Node : CustomStringConvertible , Equatable {
19
+ open var neighbors : [ Edge ]
20
20
21
- public private ( set) var label : String
22
- public var distance : Int ?
23
- public var visited : Bool
21
+ open fileprivate ( set) var label : String
22
+ open var distance : Int ?
23
+ open var visited : Bool
24
24
25
25
public init ( label: String ) {
26
26
self . label = label
27
27
neighbors = [ ]
28
28
visited = false
29
29
}
30
30
31
- public var description : String {
31
+ open var description : String {
32
32
if let distance = distance {
33
33
return " Node(label: \( label) , distance: \( distance) ) "
34
34
}
35
35
return " Node(label: \( label) , distance: infinity) "
36
36
}
37
37
38
- public var hasDistance : Bool {
38
+ open var hasDistance : Bool {
39
39
return distance != nil
40
40
}
41
41
42
- public func remove( edge: Edge ) {
42
+ open func remove( _ edge: Edge ) {
43
43
neighbors. remove ( at: neighbors. index { $0 === edge } !)
44
44
}
45
45
}
@@ -50,25 +50,25 @@ public func == (lhs: Node, rhs: Node) -> Bool {
50
50
51
51
// MARK: - Graph
52
52
53
- public class Graph : CustomStringConvertible , Equatable {
54
- public private ( set) var nodes : [ Node ]
53
+ open class Graph : CustomStringConvertible , Equatable {
54
+ open fileprivate ( set) var nodes : [ Node ]
55
55
56
56
public init ( ) {
57
57
self . nodes = [ ]
58
58
}
59
59
60
- public func addNode( label: String ) -> Node {
60
+ open func addNode( label: String ) -> Node {
61
61
let node = Node ( label: label)
62
62
nodes. append ( node)
63
63
return node
64
64
}
65
65
66
- public func addEdge( _ source: Node , neighbor: Node ) {
66
+ open func addEdge( _ source: Node , neighbor: Node ) {
67
67
let edge = Edge ( neighbor: neighbor)
68
68
source. neighbors. append ( edge)
69
69
}
70
70
71
- public var description : String {
71
+ open var description : String {
72
72
var description = " "
73
73
74
74
for node in nodes {
@@ -79,11 +79,11 @@ public class Graph: CustomStringConvertible, Equatable {
79
79
return description
80
80
}
81
81
82
- public func findNodeWithLabel( label: String ) -> Node {
82
+ open func findNodeWithLabel( label: String ) -> Node {
83
83
return nodes. filter { $0. label == label } . first!
84
84
}
85
85
86
- public func duplicate( ) -> Graph {
86
+ open func duplicate( ) -> Graph {
87
87
let duplicated = Graph ( )
88
88
89
89
for node in nodes {
0 commit comments