Debian Codegraph @

README.md

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