graph

package
v0.0.0-...-b413506 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

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

func New(nodes map[int][]int) (*Graph, error)

New creates an instance of Graph provided nodes, while also ensuring their relations are mutual and valid.

func (*Graph) AddEdge

func (g *Graph) AddEdge(a, b int) error

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

func (g *Graph) AddNode(nodeID int, connections []int) error

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

func (g *Graph) CycleExists() bool

CycleExists checks whether there is any cycle in the graph.

func (*Graph) FindShortestPath

func (g *Graph) FindShortestPath(a, b int) ([]int, error)

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

func (g *Graph) PathExists(a, b int) bool

PathExists checks whether a path between node `a` and node `b` exist.

func (*Graph) RemoveEdge

func (g *Graph) RemoveEdge(a, b int) error

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

func (g *Graph) RemoveNode(nodeID int) error

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
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL