From 24b08a332d7c5ae2bf6b1debfd89bdc92395de0d Mon Sep 17 00:00:00 2001 From: James Shubin Date: Tue, 12 Jun 2018 17:41:32 -0400 Subject: [PATCH] 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. --- pgraph/subgraph.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pgraph/subgraph.go b/pgraph/subgraph.go index 917f16b4..df1df587 100644 --- a/pgraph/subgraph.go +++ b/pgraph/subgraph.go @@ -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 {