mirror of
https://github.com/gonum/gonum.git
synced 2025-10-08 08:30:14 +08:00
graph: use int64 for node removal
This commit is contained in:

committed by
Dan Kortschak

parent
22ecbbb4f5
commit
a1b5d898fe
@@ -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.
|
||||
|
Reference in New Issue
Block a user