MCPcopy
hub / github.com/purpleidea/mgmt / AddVertex

Method AddVertex

pgraph/pgraph.go:231–253  ·  view source on GitHub ↗

AddVertex uses variadic input to add all listed vertices to the graph.

(xv ...Vertex)

Source from the content-addressed store, hash-verified

229
230// AddVertex uses variadic input to add all listed vertices to the graph.
231func (obj *Graph) AddVertex(xv ...Vertex) {
232 if obj.adjacency == nil { // initialize on first use
233 obj.adjacency = make(map[Vertex]map[Vertex]Edge)
234 }
235 if obj.revadjmap == nil { // initialize on first use
236 obj.revadjmap = make(map[Vertex]map[Vertex]Edge)
237 }
238 for _, v := range xv {
239 if v == nil {
240 panic("nil vertex")
241 }
242 // The inner maps start as nil and get allocated by AddEdge on
243 // first use. Nil maps are safe to range over, read, len() and
244 // delete() from, so only the writes in AddEdge need to care.
245 // This halves the allocations for graphs full of vertices.
246 if _, exists := obj.adjacency[v]; !exists {
247 obj.adjacency[v] = nil
248 }
249 if _, exists := obj.revadjmap[v]; !exists {
250 obj.revadjmap[v] = nil
251 }
252 }
253}
254
255// DeleteVertex uses variadic input to delete all listed vertices from the
256// graph.

Callers 15

CopyWithFnMethod · 0.95
AddEdgeMethod · 0.95
FilterGraphWithFnMethod · 0.95
buildChainFunction · 0.95
buildFanoutFunction · 0.95
buildFaninFunction · 0.95
buildLayeredFunction · 0.95
buildRandomDAGFunction · 0.95
buildDisconnectedChainsFunction · 0.95
TestAddEdge1Function · 0.95
TestFilterGraph2Function · 0.95
TestFilterGraph3Function · 0.95

Calls

no outgoing calls

Tested by 15

buildChainFunction · 0.76
buildFanoutFunction · 0.76
buildFaninFunction · 0.76
buildLayeredFunction · 0.76
buildRandomDAGFunction · 0.76
buildDisconnectedChainsFunction · 0.76
TestAddEdge1Function · 0.76
TestFilterGraph2Function · 0.76
TestFilterGraph3Function · 0.76
TestHasPath1Function · 0.76
TestGraphCmp1Function · 0.76
TestReverseIndex1Function · 0.76