MCPcopy
hub / github.com/docker/compose / AddEdge

Method AddEdge

pkg/compose/dependencies.go:309–332  ·  view source on GitHub ↗

AddEdge adds a relationship of dependency between vertices `source` and `destination`

(source string, destination string)

Source from the content-addressed store, hash-verified

307
308// AddEdge adds a relationship of dependency between vertices `source` and `destination`
309func (g *Graph) AddEdge(source string, destination string) error {
310 g.lock.Lock()
311 defer g.lock.Unlock()
312
313 sourceVertex := g.Vertices[source]
314 destinationVertex := g.Vertices[destination]
315
316 if sourceVertex == nil {
317 return fmt.Errorf("could not find %s: %w", source, api.ErrNotFound)
318 }
319 if destinationVertex == nil {
320 return fmt.Errorf("could not find %s: %w", destination, api.ErrNotFound)
321 }
322
323 // If they are already connected
324 if _, ok := sourceVertex.Children[destination]; ok {
325 return nil
326 }
327
328 sourceVertex.Children[destination] = destinationVertex
329 destinationVertex.Parents[source] = sourceVertex
330
331 return nil
332}
333
334// Leaves returns the slice of leaves of the graph
335func (g *Graph) Leaves() []*Vertex {

Callers 2

TestWith_RootNodesAndUpFunction · 0.95
NewGraphFunction · 0.95

Calls 1

LockMethod · 0.45

Tested by 1

TestWith_RootNodesAndUpFunction · 0.76