Documentation ¶
Index ¶
- type Chain
- type DijkstraSearcher
- type DirectedGraph
- func (d *DirectedGraph) AddEdge(start, end string, cost int) error
- func (d *DirectedGraph) AddNode(n *Node) error
- func (d *DirectedGraph) GetEdgeCost(start, end string) (int, error)
- func (d *DirectedGraph) GetNode(key string) (*Node, error)
- func (d *DirectedGraph) RemoveEdge(start, end string) error
- func (d *DirectedGraph) RemoveNode(key string) error
- type Node
- type Searcher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Chain ¶
type Chain struct {
// contains filtered or unexported fields
}
Chain is a method chaining struct for a directed graph.
func NewDirectedGraphChain ¶
func NewDirectedGraphChain() *Chain
func (*Chain) DirectedGraph ¶
func (c *Chain) DirectedGraph() (*DirectedGraph, error)
DirectedGraph returns the directed graph built by the chain, or the error if any occurred in building.
type DijkstraSearcher ¶
type DijkstraSearcher struct { }
func (*DijkstraSearcher) ShortestPath ¶
func (d *DijkstraSearcher) ShortestPath(graph *DirectedGraph, startKey, targetKey string) []*Node
ShortestPath calculates the shortest path (by cost) from start to end.
type DirectedGraph ¶
type DirectedGraph struct {
// contains filtered or unexported fields
}
DirectedGraph represents a directed graph as an adjacency list.
func NewDirectedGraph ¶
func NewDirectedGraph() *DirectedGraph
NewDirectedGraph returns an empty directed graph.
func (*DirectedGraph) AddEdge ¶
func (d *DirectedGraph) AddEdge(start, end string, cost int) error
AddEdge adds a new edge to the graph with a cost.
func (*DirectedGraph) AddNode ¶
func (d *DirectedGraph) AddNode(n *Node) error
AddNode adds a new node to the graph.
func (*DirectedGraph) GetEdgeCost ¶
func (d *DirectedGraph) GetEdgeCost(start, end string) (int, error)
GetEdgeCost returns the cost of the edge between start and end nodes
func (*DirectedGraph) GetNode ¶
func (d *DirectedGraph) GetNode(key string) (*Node, error)
AddNode adds a new node to the graph.
func (*DirectedGraph) RemoveEdge ¶
func (d *DirectedGraph) RemoveEdge(start, end string) error
RemoveEdge deletes a an edge from the graph.
func (*DirectedGraph) RemoveNode ¶
func (d *DirectedGraph) RemoveNode(key string) error
RemoveNode deletes a node (by key) and any associated edges from the graph.
type Searcher ¶
type Searcher interface {
ShortestPath(graph *DirectedGraph, startKey, targetKey string) []*Node
}