Documentation
¶
Index ¶
- type Graph
- func (g *Graph) AddEdge(a, b int) error
- func (g *Graph) AddNode(nodeID int, connections []int) error
- func (g *Graph) CycleExists() bool
- func (g *Graph) FindShortestPath(a, b int) ([]int, error)
- func (g *Graph) PathExists(a, b int) bool
- func (g *Graph) RemoveEdge(a, b int) error
- func (g *Graph) RemoveNode(nodeID int) error
- type LookupNode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Graph ¶
type Graph struct {
// contains filtered or unexported fields
}
func New ¶
New creates an instance of Graph provided nodes, while also ensuring their relations are mutual and valid.
func (*Graph) AddEdge ¶
AddEdge adds an edge to the graph between node `a` and node `b`, if error occurs during the process, the error is returned and no changes are made to the graph.
func (*Graph) AddNode ¶
AddNode adds a new node to the graph provided its id and connections, if error occurs during the process, the error is returned and no changes are made to the graph.
func (*Graph) CycleExists ¶
CycleExists checks whether there is any cycle in the graph.
func (*Graph) FindShortestPath ¶
FindShortestPath returns the shortest path between node `a` and node `b`. If multiple same length paths exist, it will return one of them without any defined logic.
func (*Graph) PathExists ¶
PathExists checks whether a path between node `a` and node `b` exist.
func (*Graph) RemoveEdge ¶
RemoveEdge removes an edge from the graph provided node `a` and node `b`, only returns error if the edge already does not exist, indicating that no removing operation was needed to be performed.
func (*Graph) RemoveNode ¶
RemoveNode removes a node from the graph provided its id, only returns error if the node already does not exist, indicating that no removing operation was needed to be performed.
type LookupNode ¶
type LookupNode struct { ID int Parent *LookupNode }