File tree Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -48,20 +48,23 @@ type SimpleGraph struct {
4848 v , e int
4949}
5050
51+ // V returns the number of vertices in the SimpleGraph
5152func (g * SimpleGraph ) V () int {
5253 g .mutex .RLock ()
5354 defer g .mutex .RUnlock ()
5455
5556 return g .v
5657}
5758
59+ // E returns the number of edges in the SimpleGraph
5860func (g * SimpleGraph ) E () int {
5961 g .mutex .RLock ()
6062 defer g .mutex .RUnlock ()
6163
6264 return g .e
6365}
6466
67+ // AddEdge will create an edge between vertices v and w
6568func (g * SimpleGraph ) AddEdge (v , w interface {}) error {
6669 g .mutex .Lock ()
6770 defer g .mutex .Unlock ()
@@ -83,6 +86,7 @@ func (g *SimpleGraph) AddEdge(v, w interface{}) error {
8386 return nil
8487}
8588
89+ // Adj returns the list of all vertices connected to v
8690func (g * SimpleGraph ) Adj (v interface {}) ([]interface {}, error ) {
8791 g .mutex .RLock ()
8892 defer g .mutex .RUnlock ()
@@ -101,6 +105,7 @@ func (g *SimpleGraph) Adj(v interface{}) ([]interface{}, error) {
101105 return adj , nil
102106}
103107
108+ // Degree returns the number of vertices connected to v
104109func (g * SimpleGraph ) Degree (v interface {}) (int , error ) {
105110 g .mutex .RLock ()
106111 defer g .mutex .RUnlock ()
@@ -121,6 +126,7 @@ func (g *SimpleGraph) addVertex(v interface{}) {
121126 }
122127}
123128
129+ // NewSimpleGraph creates and returns a SimpleGraph
124130func NewSimpleGraph () * SimpleGraph {
125131 return & SimpleGraph {
126132 adjacencyList : make (map [interface {}]map [interface {}]struct {}),
You can’t perform that action at this time.
0 commit comments