File: README.md

package info (click to toggle)
golang-pault-go-topsort 0.0~git20160529.f98d2ad-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 72 kB
  • sloc: makefile: 2
file content (49 lines) | stat: -rw-r--r-- 875 bytes parent folder | download
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/go/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 can 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
	 */
}
```