MCPcopy Index your code
hub / github.com/devspace-sh/devspace / InsertNodeAt

Method InsertNodeAt

pkg/devspace/dependency/graph/graph.go:59–81  ·  view source on GitHub ↗

InsertNodeAt inserts a new node at the given parent position

(parentID string, id string, data interface{})

Source from the content-addressed store, hash-verified

57
58// InsertNodeAt inserts a new node at the given parent position
59func (g *Graph) InsertNodeAt(parentID string, id string, data interface{}) (*Node, error) {
60 parentNode, ok := g.Nodes[parentID]
61 if !ok {
62 return nil, errors.Errorf("Parent %s does not exist", parentID)
63 }
64 if existingNode, ok := g.Nodes[id]; ok {
65 err := g.AddEdge(parentNode.ID, existingNode.ID)
66 if err != nil {
67 return nil, err
68 }
69
70 return existingNode, nil
71 }
72
73 node := NewNode(id, data)
74
75 g.Nodes[node.ID] = node
76
77 parentNode.Childs = append(parentNode.Childs, node)
78 node.Parents = append(node.Parents, parentNode)
79
80 return node, nil
81}
82
83// RemoveNode removes a node with no children in the graph
84func (g *Graph) RemoveNode(id string) error {

Callers 4

resolveRecursiveMethod · 0.80
TryLockDependenciesMethod · 0.80
TestGraphFunction · 0.80
insertVariableGraphMethod · 0.80

Calls 3

AddEdgeMethod · 0.95
NewNodeFunction · 0.70
ErrorfMethod · 0.45

Tested by 1

TestGraphFunction · 0.64