pgraph: Filter graph should preserve vertices without an edge

There was a bug in filter graph that caused it to not preserve any
vertices that weren't bound to another with an edge. This fixes the bug
and adds a test too.
This commit is contained in:
James Shubin
2024-01-07 17:53:31 -05:00
parent d61936c06d
commit cb021e3a25
2 changed files with 27 additions and 1 deletions

View File

@@ -506,9 +506,13 @@ func (g *Graph) FilterGraph(name string, vertices []Vertex) (*Graph, error) {
return nil, errwrap.Wrapf(err, "could not run FilterGraph() properly")
}
for k1, x := range g.adjacency {
contains := VertexContains(k1, vertices)
if contains {
newGraph.AddVertex(k1)
}
for k2, e := range x {
//log.Printf("Filter: %s -> %s # %s", k1.Name, k2.Name, e.Name)
if VertexContains(k1, vertices) || VertexContains(k2, vertices) {
if contains || VertexContains(k2, vertices) {
newGraph.AddEdge(k1, k2, e)
}
}