File tree 1 file changed +6
-0
lines changed
1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -48,20 +48,23 @@ type SimpleGraph struct {
48
48
v , e int
49
49
}
50
50
51
+ // V returns the number of vertices in the SimpleGraph
51
52
func (g * SimpleGraph ) V () int {
52
53
g .mutex .RLock ()
53
54
defer g .mutex .RUnlock ()
54
55
55
56
return g .v
56
57
}
57
58
59
+ // E returns the number of edges in the SimpleGraph
58
60
func (g * SimpleGraph ) E () int {
59
61
g .mutex .RLock ()
60
62
defer g .mutex .RUnlock ()
61
63
62
64
return g .e
63
65
}
64
66
67
+ // AddEdge will create an edge between vertices v and w
65
68
func (g * SimpleGraph ) AddEdge (v , w interface {}) error {
66
69
g .mutex .Lock ()
67
70
defer g .mutex .Unlock ()
@@ -83,6 +86,7 @@ func (g *SimpleGraph) AddEdge(v, w interface{}) error {
83
86
return nil
84
87
}
85
88
89
+ // Adj returns the list of all vertices connected to v
86
90
func (g * SimpleGraph ) Adj (v interface {}) ([]interface {}, error ) {
87
91
g .mutex .RLock ()
88
92
defer g .mutex .RUnlock ()
@@ -101,6 +105,7 @@ func (g *SimpleGraph) Adj(v interface{}) ([]interface{}, error) {
101
105
return adj , nil
102
106
}
103
107
108
+ // Degree returns the number of vertices connected to v
104
109
func (g * SimpleGraph ) Degree (v interface {}) (int , error ) {
105
110
g .mutex .RLock ()
106
111
defer g .mutex .RUnlock ()
@@ -121,6 +126,7 @@ func (g *SimpleGraph) addVertex(v interface{}) {
121
126
}
122
127
}
123
128
129
+ // NewSimpleGraph creates and returns a SimpleGraph
124
130
func NewSimpleGraph () * SimpleGraph {
125
131
return & SimpleGraph {
126
132
adjacencyList : make (map [interface {}]map [interface {}]struct {}),
You can’t perform that action at this time.
0 commit comments