Skip to content

Commit 720d4b4

Browse files
committed
Add comments to exported methods
1 parent cb665b6 commit 720d4b4

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

graph/simple.go

+6
Original file line numberDiff line numberDiff 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
5152
func (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
5860
func (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
6568
func (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
8690
func (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
104109
func (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
124130
func NewSimpleGraph() *SimpleGraph {
125131
return &SimpleGraph{
126132
adjacencyList: make(map[interface{}]map[interface{}]struct{}),

0 commit comments

Comments
 (0)