Documentation
¶
Index ¶
- func NodeInGraph[Node comparable, Edge any](g Graph[Node, Edge], n Node) bool
- func NodesFrom[Node comparable, Edge any](g Graph[Node, Edge], n Node) iter.Seq[Node]
- func ShortestPath[Node comparable, Edge any](g Graph[Node, Edge], from, to Node) []Edge
- type EnumerableGraph
- type EnumerableSimpleGraph
- type Graph
- type Simple
- type SimpleGraph
- type Weighted
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NodeInGraph ¶
func NodeInGraph[Node comparable, Edge any](g Graph[Node, Edge], n Node) bool
func NodesFrom ¶
func NodesFrom[Node comparable, Edge any](g Graph[Node, Edge], n Node) iter.Seq[Node]
func ShortestPath ¶
func ShortestPath[Node comparable, Edge any](g Graph[Node, Edge], from, to Node) []Edge
ShortestPath returns the shortest path from -> to in the graph g using Dijkstra's algorithm. The returned slice holds all the edges leading from the source to the destination.
Types ¶
type EnumerableGraph ¶
type EnumerableGraph[Node comparable, Edge any] interface { Graph[Node, Edge] AllNodes() iter.Seq[Node] }
type EnumerableSimpleGraph ¶
type EnumerableSimpleGraph[Node comparable, Edge any] interface { SimpleGraph[Node, Edge] AllNodes() iter.Seq[Node] }
type Graph ¶
type Graph[Node comparable, Edge any] interface { // TODO return iterator? // TODO it's useful to be able to tell if a given node // is actually part of the graph or not. Could // say that returning nil slice signifies non-presence, // or (probably better) return ([]Edge, bool). EdgesFrom(Node) ([]Edge, bool) Nodes(Edge) (from, to Node) CmpNode(n0, n1 Node) int }
type Simple ¶
Simple implements Graph for a concrete set of comparable nodes.
func (*Simple[Node]) AddEdge ¶
func (g *Simple[Node]) AddEdge(from, to Node)
AddEdge adds nodes from and to, and adds an edge from -> to. You don't need to call AddNode first; the nodes will be implicitly added if they don't already exist. The direction means that from depends on to; i.e. to will appear before from in the sorted output. Cycles are allowed.
func (*Simple[Node]) AddNode ¶
func (g *Simple[Node]) AddNode(n Node)
AddNode adds a node. Typically this is only used to add nodes with no incoming or outgoing edges.
type SimpleGraph ¶
type SimpleGraph[Node comparable, Edge any] interface { Graph[Node, Edge] Edge(Node) (Edge, bool) }
SimpleGraph is a special case of Graph that only allows a single edge between any two nodes. An edge may not connect a node to itself.