graph

package
v0.2.1-0...-9c16218 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2020 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDuplicateVertex indicates that a vertex with an
	// identical id exists in the DAG.
	ErrDuplicateVertex = errors.New("vertex already exists")
	// ErrVertexNoExist indicates that an id does not correspond
	// to a vertex in the DAG.
	ErrVertexNoExist = errors.New("vertex does not exist")
	// ErrCycle indicates that there is a cycle within the graph
	ErrCycle = errors.New("cycle exists")
)

Functions

This section is empty.

Types

type DAG

type DAG struct {
	// contains filtered or unexported fields
}

DAG represents a Directed Acyclic Graph.

func New

func New() DAG

New returns a new DAG.

func (*DAG) AddVertex

func (g *DAG) AddVertex(id string, parents []string) error

AddVertex will add a vertex to the DAG with the adjacent parent verticies. Edges are assumed to travel from parents to children. If a vertex already exists, an error will be returned

func (*DAG) HasCycle

func (g *DAG) HasCycle() bool

HasCycle returns true if the graph contains a cycle.

func (DAG) TopoSort

func (g DAG) TopoSort() ([]string, error)

TopoSort performs a topological sort on the DAG and returns a slice of vertex ids in a valid topological order.

func (DAG) Validate

func (g DAG) Validate() error

Validate checks that all edges are valid. If a vertex references a non-existant vertex an error is returned. NOTE: this does not check for cycles. HasCycles does. this could maybe be a check within HasCycles and not part of the api?

Jump to

Keyboard shortcuts

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