graph: use int64 for node removal

This commit is contained in:
Dan Kortschak
2018-03-25 10:16:12 +10:30
committed by Dan Kortschak
parent 22ecbbb4f5
commit a1b5d898fe
17 changed files with 105 additions and 104 deletions

View File

@@ -65,25 +65,25 @@ func (g *DirectedGraph) AddNode(n graph.Node) {
g.nodeIDs.Use(n.ID())
}
// RemoveNode removes n from the graph, as well as any edges attached to it. If the node
// is not in the graph it is a no-op.
func (g *DirectedGraph) RemoveNode(n graph.Node) {
if _, ok := g.nodes[n.ID()]; !ok {
// RemoveNode removes the node with the given ID from the graph, as well as any edges attached
// to it. If the node is not in the graph it is a no-op.
func (g *DirectedGraph) RemoveNode(id int64) {
if _, ok := g.nodes[id]; !ok {
return
}
delete(g.nodes, n.ID())
delete(g.nodes, id)
for from := range g.from[n.ID()] {
delete(g.to[from], n.ID())
for from := range g.from[id] {
delete(g.to[from], id)
}
delete(g.from, n.ID())
delete(g.from, id)
for to := range g.to[n.ID()] {
delete(g.from[to], n.ID())
for to := range g.to[id] {
delete(g.from[to], id)
}
delete(g.to, n.ID())
delete(g.to, id)
g.nodeIDs.Release(n.ID())
g.nodeIDs.Release(id)
}
// NewLine returns a new Line from the source to the destination node.