Skip to content

aio-arch/graphlib

Repository files navigation

graphlib

Go Report Card Codecov GitHub Actions Workflow Status Minimum Go Version

A Topological sort lib.

Sorting and pruning of DAG graphs.

Ideas borrowed from python graphlib

How to install

go get -u github.com/aio-arch/graphlib

How to use

    import "github.com/aio-arch/graphlib"

    // New A graph

	// for string type
	g1 := graphlib.NewGraph[string]()

	// for int type
	g2 := graphlib.NewGraph[int]()

	// for add node and add edge
	g1.AddNode("A1")
	g1.AddNode("B2")
	g1.AddEdge("A1", "B2") // edge: A1 -> B2

	// for add mulit edge,add node inline
	g2.Add(10, 1, 9)    // edge: 1 -> 10 and 9 -> 10
	g2.Add(100, 10, 90) // edge: 10 -> 100 and 90 -> 100

	// topological order
	topo, err := graphlib.TopologicalOrder(g1)
	if err != nil {
		fmt.Println(err.Error())
	}
	fmt.Printf("Topological Order:%v\n", topo)

	// topological prune
	g3, err := graphlib.TopologicalPrune(g2, []int{10, 90})
	if err != nil {
		fmt.Println(err.Error())
	}
	_ = g3

About

Topological sort lib,Sorting and pruning of DAG graphs.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages