pgraph: Handle empty graphs when merging two

In case we choose to add an empty (nil) graph, handle it safely. This
could allow us to return nil in a lang/structs Graph method without
issue.
This commit is contained in:
James Shubin
2018-06-12 17:41:32 -04:00
parent 70ccb3022a
commit 24b08a332d

View File

@@ -66,6 +66,9 @@ func (g *Graph) AddEdgeGraphVertexLight(graph *Graph, vertex Vertex, edgeGenFn f
// or from the vertices with an indegree or outdegree equal to zero depending on
// if we specified reverse or not.
func (g *Graph) addEdgeVertexGraphHelper(vertex Vertex, graph *Graph, edgeGenFn func(v1, v2 Vertex) Edge, reverse, light bool) {
if graph == nil {
return // if the graph is empty, there's nothing to do!
}
var degree map[Vertex]int // compute all of the in/outdegree's if needed
if light && reverse {