MCPcopy Create free account
hub / github.com/DoNewsCode/core / AddEdge

Method AddEdge

dag/dag.go:47–60  ·  view source on GitHub ↗

AddEdge adds an edge to the dag. AddEdge is not concurrent safe. All vertexes and edges are expected to be added synchronously before calling Run. If the new edge leads to a cycle, AddEdge will return error.

(from, to VertexID)

Source from the content-addressed store, hash-verified

45//
46// If the new edge leads to a cycle, AddEdge will return error.
47func (d *DAG) AddEdge(from, to VertexID) error {
48 if len(d.vertexes) <= int(from) || from < 0 {
49 return errors.Errorf("invalid vertex id %d", from)
50 }
51 if to < 0 || len(d.vertexes) <= int(to) {
52 return errors.Errorf("invalid vertex id %d", to)
53 }
54 d.vertexes[from].addChild(d.vertexes[to])
55 if yes, edges := IsAcyclic(d); !yes {
56 d.vertexes[from].removeChild(d.vertexes[to])
57 return errors.Errorf("dag is not acyclic: %s", d.fmtEdges(edges))
58 }
59 return nil
60}
61
62// AddEdges adds multiple edges in one batch. See AddEdge for more details.
63func (d *DAG) AddEdges(edges Edges) error {

Callers 5

ExampleDAG_runFunction · 0.80
TestDag_addEdgeFunction · 0.80
TestDag_addEdgesFunction · 0.80
TestDag_RunFunction · 0.80

Calls 4

fmtEdgesMethod · 0.95
IsAcyclicFunction · 0.85
addChildMethod · 0.80
removeChildMethod · 0.80

Tested by 5

ExampleDAG_runFunction · 0.64
TestDag_addEdgeFunction · 0.64
TestDag_addEdgesFunction · 0.64
TestDag_RunFunction · 0.64