https://github.com/heimdalr/dag
Yet another directed acyclic graph (DAG) implementation in golang.
https://github.com/heimdalr/dag
dag directed-acyclic-graph golang golang-module
Last synced: 3 months ago
JSON representation
Yet another directed acyclic graph (DAG) implementation in golang.
- Host: GitHub
- URL: https://github.com/heimdalr/dag
- Owner: heimdalr
- License: bsd-3-clause
- Created: 2019-12-26T11:32:48.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-07-26T07:18:10.000Z (over 1 year ago)
- Last Synced: 2024-07-27T07:27:45.474Z (over 1 year ago)
- Topics: dag, directed-acyclic-graph, golang, golang-module
- Language: Go
- Homepage:
- Size: 129 KB
- Stars: 169
- Watchers: 7
- Forks: 33
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome - heimdalr/dag - Yet another directed acyclic graph (DAG) implementation in golang. (<a name="Go"></a>Go)
README
# dag
[](https://github.com/heimdalr/dag/actions?query=branch%3Amaster)
[](https://pkg.go.dev/github.com/heimdalr/dag)
[](https://goreportcard.com/report/github.com/heimdalr/dag)
[](https://gitpod.io/#https://github.com/heimdalr/dag)
[](https://github.com/heimdalr/dag/actions/workflows/codeql-analysis.yml)
[](https://bestpractices.coreinfrastructure.org/projects/6402)
Implementation of directed acyclic graphs (DAGs).
The implementation is fast and thread-safe. It prevents adding cycles or
duplicates and thereby always maintains a valid DAG. The implementation caches
descendants and ancestors to speed up subsequent calls.
## Quickstart
Running:
``` go
package main
import (
"fmt"
"github.com/heimdalr/dag"
)
func main() {
// initialize a new graph
d := NewDAG()
// init three vertices
v1, _ := d.AddVertex(1)
v2, _ := d.AddVertex(2)
v3, _ := d.AddVertex(struct{a string; b string}{a: "foo", b: "bar"})
// add the above vertices and connect them with two edges
_ = d.AddEdge(v1, v2)
_ = d.AddEdge(v1, v3)
// describe the graph
fmt.Print(d.String())
}
```
will result in something like:
```
DAG Vertices: 3 - Edges: 2
Vertices:
1
2
{foo bar}
Edges:
1 -> 2
1 -> {foo bar}
```