dag
github.com/sensimevanidus/dag
go get github.com/sensimevanidus/dag
dag

github.com/sensimevanidus/dag

DAG implementation in go

by Onur Yaman

v0.0.0-20180111145408-0e33dca99240 (see all)License:MIT
go get github.com/sensimevanidus/dag
Readme

dag

DAG implementation in Go.

Usage

Let's suppose you want to represent the following DAG (represented as a JSON dictionary):

{
    "1": ["2"],
    "2": ["3", "4"],
    "4": ["3"]
}

You should do the following:

// Initialize the graph
graph := dag.NewDAG()

// Add the vertices (Here, the first parameter is the id of the vertex,
// and the second one is its value. Right now no value is set for the
// sake of simplicity)
graph.AddVertex("1", nil)
graph.AddVertex("2", nil)
graph.AddVertex("3", nil)
graph.AddVertex("4", nil)

// Add the edges (Note that given vertices must exist before adding an
// edge between them)
graph.AddEdge("1", "2")
graph.AddEdge("2", "3")
graph.AddEdge("2", "4")
graph.AddEdge("4", "3")

Voila, that's all about it. Now you can start using the DAG as you wish.

// Get a vertex
graph.Vertex("1") // returns nil if not found

// Get children of a vertex
graph.Vertex("1").Children

// Verify that an edge exists
graph.EdgeExists("1", "2") // returns true

GitHub Stars

12

LAST COMMIT

4yrs ago

MAINTAINERS

0

CONTRIBUTORS

1

OPEN ISSUES

2

OPEN PRs

0
VersionTagPublished
v0.0.0-20180111145408-0e33dca99240
2yrs ago
No alternatives found
No tutorials found
Add a tutorial