aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/cli/internal/util/graph.go
diff options
context:
space:
mode:
author简律纯 <hsiangnianian@outlook.com>2023-04-28 01:36:55 +0800
committer简律纯 <hsiangnianian@outlook.com>2023-04-28 01:36:55 +0800
commitfc8c5fdce62fb229202659408798a7b6c98f6e8b (patch)
tree7554f80e50de4af6fd255afa7c21bcdd58a7af34 /cli/internal/util/graph.go
parentdd84b9d64fb98746a230cd24233ff50a562c39c9 (diff)
downloadHydroRoll-fc8c5fdce62fb229202659408798a7b6c98f6e8b.tar.gz
HydroRoll-fc8c5fdce62fb229202659408798a7b6c98f6e8b.zip
Diffstat (limited to 'cli/internal/util/graph.go')
-rw-r--r--cli/internal/util/graph.go35
1 files changed, 0 insertions, 35 deletions
diff --git a/cli/internal/util/graph.go b/cli/internal/util/graph.go
deleted file mode 100644
index 89de18c..0000000
--- a/cli/internal/util/graph.go
+++ /dev/null
@@ -1,35 +0,0 @@
-package util
-
-import (
- "fmt"
- "strings"
-
- "github.com/pyr-sh/dag"
-)
-
-// ValidateGraph checks that a given DAG has no cycles and no self-referential edges.
-// We differ from the underlying DAG Validate method in that we allow multiple roots.
-func ValidateGraph(graph *dag.AcyclicGraph) error {
- // We use Cycles instead of Validate because
- // our DAG has multiple roots (entrypoints).
- // Validate mandates that there is only a single root node.
- cycles := graph.Cycles()
- if len(cycles) > 0 {
- cycleLines := make([]string, len(cycles))
- for i, cycle := range cycles {
- vertices := make([]string, len(cycle))
- for j, vertex := range cycle {
- vertices[j] = vertex.(string)
- }
- cycleLines[i] = "\t" + strings.Join(vertices, ",")
- }
- return fmt.Errorf("cyclic dependency detected:\n%s", strings.Join(cycleLines, "\n"))
- }
-
- for _, e := range graph.Edges() {
- if e.Source() == e.Target() {
- return fmt.Errorf("%s depends on itself", e.Source())
- }
- }
- return nil
-}