Documentation
¶
Overview ¶
Package digraph provides an implementation of a directed graph, or "digraph"
Index ¶
- Variables
- type AdjacencyList
- type Digraph
- func (d *Digraph) AddEdge(source Vertex, target Vertex) error
- func (d *Digraph) AddVertex(vertex Vertex) error
- func (d *Digraph) DepthFirstSearch(source Vertex, target Vertex) bool
- func (d *Digraph) EdgeCount() int
- func (d *Digraph) HasEdge(source Vertex, target Vertex) bool
- func (d *Digraph) Print(root Vertex, all bool) (string, error)
- func (d *Digraph) String() string
- func (d *Digraph) VertexCount() int
- type Vertex
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCycle is returned when creating an edge between two vertices would result // in a cycle in the digraph ErrCycle = errors.New("digraph: cycle between edges") // ErrEdgeExists is returned when an edge between two vertices already exists ErrEdgeExists = errors.New("digraph: edge already exists") // ErrVertexExists is returned when a vertex with the same value already exists ErrVertexExists = errors.New("digraph: vertex already exists") // ErrVertexNotExists is returned when a vertex is used which does not exist ErrVertexNotExists = errors.New("digraph: vertex does not exist") )
Functions ¶
This section is empty.
Types ¶
type AdjacencyList ¶
type AdjacencyList struct {
// contains filtered or unexported fields
}
AdjacencyList represents a linked-list of vertices connected by edges in the digraph
func NewAdjacencyList ¶
func NewAdjacencyList() *AdjacencyList
NewAdjacencyList returns a new AdjacencyList with its internal list initialized
func (*AdjacencyList) Adjacent ¶
func (a *AdjacencyList) Adjacent() []Vertex
Adjacent returns all vertices from the adjacency list
func (*AdjacencyList) Search ¶
func (a *AdjacencyList) Search(target Vertex) Vertex
Search traverses the adjancency list and attempts to find a specified vertex
type Digraph ¶
type Digraph struct {
// contains filtered or unexported fields
}
Digraph represents a "digraph", or directed graph data structure
func New ¶
func New() *Digraph
New creates a new acyclic Digraph, and initializes its adjacency list
func (*Digraph) AddEdge ¶
AddEdge tries to add a new edge between two vertices on the adjacency list
func (*Digraph) AddVertex ¶
AddVertex tries to add a new vertex to the root of the adjacency list on the digraph
func (*Digraph) DepthFirstSearch ¶
DepthFirstSearch searches the digraph for the target vertex, using the Depth-First Search algorithm, and returning true if a path to the target is found
func (*Digraph) HasEdge ¶
HasEdge determines if the digraph has an existing edge between source and target, returning true if it does, or false if it does not
func (*Digraph) String ¶
String retruns a string representation of the digraph, from the first vertex or "root"
func (*Digraph) VertexCount ¶
VertexCount returns the number of vertices in the digraph