graph

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2015 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DAG

type DAG struct {
	Root      *Vertex
	Adjacency map[*Vertex]*list.List
}

DAG is a Directed Acyclic Graph implemented with an adjacency list.

func NewDAG

func NewDAG(v interface{}) *DAG

NewDAG constructs a new graph with a single root vertex.

func (*DAG) Add

func (g *DAG) Add(v interface{}) *Vertex

Add inserts a vertex holding a value v in the graph.

func (*DAG) AddEdge

func (g *DAG) AddEdge(to, from *Vertex) error

AddEdge inserts an directed edge between two vertecies.

func (*DAG) BFS

func (g *DAG) BFS(fn WalkFunc) error

BFS walks the graph in breadth-first order.

func (*DAG) DFS

func (g *DAG) DFS(fn WalkFunc) error

DFS walks the graph in depth-first order.

func (*DAG) Edges

func (g *DAG) Edges(v *Vertex) []*Vertex

Edges returns the outgoing edges for v.

func (*DAG) Get

func (g *DAG) Get(v interface{}) (*Vertex, bool)

Get returns the vertex for the corresponding value.

func (*DAG) ReverseDFS

func (g *DAG) ReverseDFS(fn WalkFunc) error

ReverseDFS walks the graph in reverse depth-first order.

type Vertex

type Vertex struct {
	Value interface{}
}

Vertex is a vertex for DAG.

type WalkFunc

type WalkFunc func(*Vertex) error

WalkFunc is a common func for all graph walking methods.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL