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

Method HasCycles

pkg/compose/dependencies.go:405–423  ·  view source on GitHub ↗

HasCycles detects cycles in the graph

()

Source from the content-addressed store, hash-verified

403
404// HasCycles detects cycles in the graph
405func (g *Graph) HasCycles() (bool, error) {
406 discovered := []string{}
407 finished := []string{}
408
409 for _, vertex := range g.Vertices {
410 path := []string{
411 vertex.Key,
412 }
413 if !slices.Contains(discovered, vertex.Key) && !slices.Contains(finished, vertex.Key) {
414 var err error
415 discovered, finished, err = g.visit(vertex.Key, path, discovered, finished)
416 if err != nil {
417 return true, err
418 }
419 }
420 }
421
422 return false, nil
423}
424
425func (g *Graph) visit(key string, path []string, discovered []string, finished []string) ([]string, []string, error) {
426 discovered = append(discovered, key)

Callers 1

NewGraphFunction · 0.95

Calls 1

visitMethod · 0.95

Tested by

no test coverage detected