Documentation ¶
Index ¶
- type CycleError
- type Graph
- func (g *Graph[Key]) AddEdge(from Key, to Key)
- func (g *Graph[Key]) AddNode(key Key)
- func (g *Graph[Key]) ContainsNode(key Key) bool
- func (g *Graph[Key]) DOTString(keyToString func(Key) string) (string, error)
- func (g *Graph[Key]) NumEdges() int
- func (g *Graph[Key]) NumNodes() int
- func (g *Graph[Key]) TopoSort(start Key) ([]Key, error)
- func (g *Graph[Key]) WalkEdges(f func(Key, Key) error) error
- func (g *Graph[Key]) WalkNodes(f func(Key, []Key, []Key) error) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CycleError ¶
type CycleError[Key comparable] struct { Keys []Key }
CycleError is an error if the Graph had a cycle.
type Graph ¶
type Graph[Key comparable] struct { // contains filtered or unexported fields }
Graph is a directed acyclic graph structure with comparable keys.
func NewGraph ¶
func NewGraph[Key comparable]() *Graph[Key]
NewGraph returns a new Graph.
Graphs can also safely be instantiated with &Graph{}.
func (*Graph[Key]) ContainsNode ¶
ContainsNode returns true if the graph contains the given node.
func (*Graph[Key]) DOTString ¶
DOTString returns a DOT representation of the graph.
keyToString is used to print out the label for each node. https://graphviz.org/doc/info/lang.html
func (*Graph[Key]) TopoSort ¶
TopoSort topologically sorts the nodes in the Graph starting at the given key.
Returns a *CycleError if there is a cycle in the graph.
func (*Graph[Key]) WalkEdges ¶
WalkEdges visits each edge in the Graph starting at the source keys.
f is called for each directed edge. The first argument is the source node, the second is the destination node.
Returns a *CycleError if there is a cycle in the graph.