Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type WeightFunc ¶
WeightFunc is a function that calculates the weight of an edge.
Parameters:
- from: the source vertex.
- to: the destination vertex.
Returns:
- float64: the weight of the edge.
- bool: true if the edge exists, otherwise false.
type WeightedGraph ¶
type WeightedGraph[T uc.Objecter] struct { // Vertices in the graph. Vertices []T // Edges in the graph. Edges [][]*float64 }
WeightedGraph represents a graph.
func NewWeightedGraph ¶
func NewWeightedGraph[T uc.Objecter](vertices []T, f WeightFunc[T]) *WeightedGraph[T]
NewWeightedGraph creates a new graph with the given vertices.
Parameters:
- vertices: vertices in the graph.
Returns:
- *WeightedGraph: the new graph.
func (*WeightedGraph[T]) AdjacentOf ¶
func (g *WeightedGraph[T]) AdjacentOf(from T) []T
AdjacentOf returns the adjacent vertices of the given vertex.
Parameters:
- from: the source vertex.
Returns:
- []T: the adjacent vertices.
func (*WeightedGraph[T]) IndexOf ¶
func (g *WeightedGraph[T]) IndexOf(elem T) int
IndexOf returns the index of the given element in the graph.
Parameters:
- elem: the element to find.
Returns:
- int: the index of the element, or -1 if not found.
func (*WeightedGraph[T]) MakeTree ¶
func (g *WeightedGraph[T]) MakeTree(root T, info uc.Objecter, f tlt.NextsFunc[T]) (*tr.Tree[T], error)
MakeTree creates a tree of the graph with the given root.
Parameters:
- root: the root of the tree.
- f: the nexts function.
Returns:
- *WeightedGraphTree: the tree of the graph.
- error: an error if the tree creation fails.
Click to show internal directories.
Click to hide internal directories.