dfs

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2014 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Contains algos and logic related to depth-first graph traversal.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindSources

func FindSources(g gogl.Digraph) (sources []gogl.Vertex, err error)

Finds all source vertices (vertices with no incoming edges) in the given directed graph.

func Search(g gogl.Graph, target gogl.Vertex, start gogl.Vertex) (path []gogl.Vertex, err error)

Performs a depth-first search for the given target vertex in the provided graph, beginning from the given start vertex.

A slice of vertices is returned, identifying the path from the start to the target vertex. If no path can be found, the returned slice is nil and an error is returned instead.

func Toposort

func Toposort(g gogl.Graph, start ...gogl.Vertex) ([]gogl.Vertex, error)

Performs a topological sort using the provided graph. The third variadic parameter defines a set of vertices to start from; vertices unreachable from this starting set will not be included in the final sorted output.

If no starting vertices are provided, then a list of source vertices is built via FindSources(), and that set is used as the starting point. Because FindSources() requires a Digraph, an error will be returned if a non-directed graph is provided without any start vertices.

Types

type TslVisitor

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

func (*TslVisitor) GetTsl

func (vis *TslVisitor) GetTsl() ([]gogl.Vertex, error)

func (*TslVisitor) OnBackEdge

func (vis *TslVisitor) OnBackEdge(vertex gogl.Vertex)

func (*TslVisitor) OnExamineEdge

func (vis *TslVisitor) OnExamineEdge(edge gogl.Edge)

func (*TslVisitor) OnFinishVertex

func (vis *TslVisitor) OnFinishVertex(vertex gogl.Vertex)

func (*TslVisitor) OnStartVertex

func (vis *TslVisitor) OnStartVertex(vertex gogl.Vertex)

type Visitor

type Visitor interface {
	OnBackEdge(vertex gogl.Vertex)
	OnStartVertex(vertex gogl.Vertex)
	OnExamineEdge(edge gogl.Edge)
	OnFinishVertex(vertex gogl.Vertex)
}

func Traverse

func Traverse(g gogl.Graph, visitor Visitor, start ...gogl.Vertex) (Visitor, error)

Traverses the given graph in a depth-first manner, using the given visitor and starting from the given vertices.

Jump to

Keyboard shortcuts

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