Documentation
¶
Index ¶
- Variables
- type BestPath
- type BestPaths
- type Graph
- func (g *Graph) AddArc(src, dest int, distance uint64) error
- func (g *Graph) AddEmptyVertex(index int) error
- func (g *Graph) AddNewEmptyVertex() (index int)
- func (g *Graph) AddVertex(index int, vertexArcs map[int]uint64) error
- func (g *Graph) AddVertexAndArcs(index int, vertexArcs map[int]uint64) error
- func (g Graph) Export() (string, error)
- func (g Graph) GetArc(src, dest int) (uint64, error)
- func (g Graph) GetVertexArcs(index int) (map[int]uint64, error)
- func (g Graph) Longest(src, dest int) (BestPath[int], error)
- func (g Graph) LongestAll(src, dest int) (BestPaths[int], error)
- func (g *Graph) RemoveArc(src, dest int) error
- func (g *Graph) RemoveVertex(index int) error
- func (g *Graph) RemoveVertexAndArcs(index int) error
- func (g Graph) Shortest(src, dest int) (BestPath[int], error)
- func (g Graph) ShortestAll(src, dest int) (BestPaths[int], error)
- type MappedGraph
- func (mg *MappedGraph[T]) AddArc(src, dest T, distance uint64) error
- func (mg *MappedGraph[T]) AddEmptyVertex(item T) error
- func (mg *MappedGraph[T]) AddVertex(item T, vertexArcs map[T]uint64) error
- func (mg *MappedGraph[T]) AddVertexAndArcs(item T, vertexArcs map[T]uint64) error
- func (mg MappedGraph[T]) Export() (string, error)
- func (mg MappedGraph[T]) GetArc(src, dest T) (uint64, error)
- func (mg *MappedGraph[T]) GetVertexArcs(item T) (map[T]uint64, error)
- func (mg MappedGraph[T]) Longest(src, dest T) (BestPath[T], error)
- func (mg MappedGraph[T]) LongestAll(src, dest T) (BestPaths[T], error)
- func (mg *MappedGraph[T]) RemoveArc(src, dest T) error
- func (mg *MappedGraph[T]) RemoveVertex(item T) error
- func (mg *MappedGraph[T]) RemoveVertexAndArcs(item T) error
- func (mg MappedGraph[T]) Shortest(src, dest T) (BestPath[T], error)
- func (mg MappedGraph[T]) ShortestAll(src, dest T) (BestPaths[T], error)
Constants ¶
This section is empty.
Variables ¶
var ErrArcHanging = errors.New("arc will be left hanging")
var ErrArcNotFound = errors.New("arc not found")
var ErrGraphNotValid = errors.New("graph is not valid")
var ErrLoopDetected = errors.New("infinite loop detected")
var ErrMapNotFound = errors.New("mapping error, can not find mapped vertex")
var ErrNoPath = errors.New("no path found")
var ErrVertexAlreadyExists = errors.New("vertex already exists")
var ErrVertexNegative = errors.New("vertex is negative")
var ErrVertexNotFound = errors.New("vertex not found")
var ErrWrongFormat = errors.New("wrong source format")
Functions ¶
This section is empty.
Types ¶
type BestPaths ¶
func (BestPaths[T]) SmallestPath ¶
type Graph ¶
type Graph struct {
// contains filtered or unexported fields
}
Graph contains all the graph details (verticies and arcs)
func Generate ¶
Generate generates a graph with a moderate amount of connections with semi random weights
func Import ¶
Import imports a graph from the specified file returns the Graph, a map for if the nodes are not integers and an error if needed.
func (*Graph) AddArc ¶
AddArc adds an arc from src to dest with the specified distance will error if the arc already exists (remove then add)
func (*Graph) AddEmptyVertex ¶
AddVertex adds a single vertex at the specified index
func (*Graph) AddNewEmptyVertex ¶
AddNewVertex adds a new vertex at the next available index
func (*Graph) AddVertex ¶
AddVertex adds or overwrites a vertex with specified arcs, if the destination of an arc does not exist, it will error. If arc destinations should be added, use AddVertexAndArcs instead
func (*Graph) AddVertexAndArcs ¶
AddVertexAndArcs adds or overwrites a vertex with specified arcs, if the destination of an arc does not exist, it will be added.
func (Graph) GetVertexArcs ¶
GetVertexArcs gets all the arcs from vertex index
func (Graph) LongestAll ¶
LongestAll calculates all of the longest paths from src to dest
func (*Graph) RemoveVertex ¶
RemoveVertex removes the vertex at index, fails if there are still arcs pointing to the vertex. To remove all arcs also, use RemoveVertexAndArcs
func (*Graph) RemoveVertexAndArcs ¶
RemoveVertexAndArcs removes the vertex at index and all arcs pointing to it
type MappedGraph ¶
type MappedGraph[T comparable] struct { // contains filtered or unexported fields }
func ImportStringMapped ¶
func ImportStringMapped(data string) (mg MappedGraph[string], err error)
func NewMappedGraph ¶
func NewMappedGraph[T comparable]() MappedGraph[T]
NewMappedGraph creates a new empty mapped graph
func (*MappedGraph[T]) AddArc ¶
func (mg *MappedGraph[T]) AddArc(src, dest T, distance uint64) error
AddArc adds an arc between two vertices
func (*MappedGraph[T]) AddEmptyVertex ¶
func (mg *MappedGraph[T]) AddEmptyVertex(item T) error
AddEmptyVertex adds a single empty vertex
func (*MappedGraph[T]) AddVertex ¶
func (mg *MappedGraph[T]) AddVertex(item T, vertexArcs map[T]uint64) error
AddVertex adds a vertex with specified arcs, if the destination of an arc does not exist, it will error. If arc destinations should be added, use AddVertexAndArcs instead
func (*MappedGraph[T]) AddVertexAndArcs ¶
func (mg *MappedGraph[T]) AddVertexAndArcs(item T, vertexArcs map[T]uint64) error
AddVertexAndArcs adds a vertex with specified arcs, if the destination of an arc does not exist, it will be added.
func (MappedGraph[T]) Export ¶
func (mg MappedGraph[T]) Export() (string, error)
func (MappedGraph[T]) GetArc ¶
func (mg MappedGraph[T]) GetArc(src, dest T) (uint64, error)
GetArc gets the distance from src to dest
func (*MappedGraph[T]) GetVertexArcs ¶
func (mg *MappedGraph[T]) GetVertexArcs(item T) (map[T]uint64, error)
GetVertex gets the reference of the specified vertex. An error is thrown if there is no vertex with that index/ID.
func (MappedGraph[T]) Longest ¶
func (mg MappedGraph[T]) Longest(src, dest T) (BestPath[T], error)
func (MappedGraph[T]) LongestAll ¶
func (mg MappedGraph[T]) LongestAll(src, dest T) (BestPaths[T], error)
func (*MappedGraph[T]) RemoveArc ¶
func (mg *MappedGraph[T]) RemoveArc(src, dest T) error
RemoveArc removes the arc between two vertices
func (*MappedGraph[T]) RemoveVertex ¶
func (mg *MappedGraph[T]) RemoveVertex(item T) error
func (*MappedGraph[T]) RemoveVertexAndArcs ¶
func (mg *MappedGraph[T]) RemoveVertexAndArcs(item T) error
func (MappedGraph[T]) Shortest ¶
func (mg MappedGraph[T]) Shortest(src, dest T) (BestPath[T], error)
func (MappedGraph[T]) ShortestAll ¶
func (mg MappedGraph[T]) ShortestAll(src, dest T) (BestPaths[T], error)