1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
topsort
=======
This package provides a handy interface to do a topological sort of
some data in a pretty lightweight way.
Example
-------
```go
package main
import (
"fmt"
"pault.ag/x/topsort"
)
func main() {
network := topsort.NewNetwork()
network.AddNode("watch tv while eating", nil)
network.AddNode("make dinner", nil)
network.AddNode("clean my kitchen", nil)
/* Right, so the order of operations is next */
network.AddEdge("clean my kitchen", "make dinner")
// I need to clean the kitchen before I make dinner.
network.AddEdge("make dinner", "watch tv while eating")
// Need to make dinner before I cean eat it.
nodes, err := network.Sort()
if err != nil {
panic(err)
}
for _, step := range nodes {
fmt.Printf(" -> %s\n", step.Name)
}
/* Output is:
*
* -> clean my kitchen
* -> make dinner
* -> watch tv while eating
*/
}
```
|