/dag

Golang DAG

Primary LanguageGoMozilla Public License 2.0MPL-2.0

dag

This is a slightly modified version of the Terraform dag code with the Terraform dependencies removed.

Example

package main

import (
	"fmt"
	"time"

	"github.com/silas/dag"
)

func main() {
	g := &dag.AcyclicGraph{}

	p := "<complete>"

	g.Add(p)

	g.Add("a")
	g.Connect(dag.BasicEdge(p, "a"))

	g.Add("b")
	g.Connect(dag.BasicEdge(p, "b"))
	g.Connect(dag.BasicEdge("b", "a"))

	g.Add("c")
	g.Connect(dag.BasicEdge(p, "c"))
	g.Connect(dag.BasicEdge("c", "a"))

	if err := g.Validate(); err != nil {
		panic(err)
	}

	g.Walk(func(v dag.Vertex) (d dag.Diagnostics) {
		key := v.(string)

		fmt.Println(key)
		time.Sleep(2 * time.Second)

		return
	})
}