https://github.com/akihirosuda/go-dag
Minimalistic DAG utility with concurrent scheduler
https://github.com/akihirosuda/go-dag
Last synced: 8 months ago
JSON representation
Minimalistic DAG utility with concurrent scheduler
- Host: GitHub
- URL: https://github.com/akihirosuda/go-dag
- Owner: AkihiroSuda
- License: apache-2.0
- Created: 2017-04-12T08:44:34.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-04-12T08:44:46.000Z (over 8 years ago)
- Last Synced: 2024-10-12T18:58:01.923Z (about 1 year ago)
- Language: Go
- Size: 7.81 KB
- Stars: 21
- Watchers: 4
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-dag
[](https://travis-ci.org/AkihiroSuda/go-dag)
[](https://godoc.org/github.com/AkihiroSuda/go-dag)Minimalistic DAG utility with concurrent scheduler
## Example
See [scheduler/scheduler_test.go](scheduler/scheduler_test.go).
```
0 1
| |
2 3
|
/ \
4 5
``````go
import (
"github.com/AkihiroSuda/go-dag"
"github.com/AkihiroSuda/go-dag/scheduler"
)g := &dag.Graph{
Nodes: []dag.Node{0, 1, 2, 3, 4, 5},
Edges: []dag.Edge{
{Depender: 2, Dependee: 0},
{Depender: 3, Dependee: 1},
{Depender: 4, Dependee: 2},
{Depender: 5, Dependee: 2},
},
}
concurrency := 0
scheduler.Execute(g, concurrency, func(n dag.Node) { appendTo(got, n) })
assert(t, indexOf(got, 0) < indexOf(got, 2))
assert(t, indexOf(got, 2) < indexOf(got, 4))
assert(t, indexOf(got, 2) < indexOf(got, 5))
assert(t, indexOf(got, 1) < indexOf(got, 3))
```