Documentation
¶
Index ¶
- type Graph
- func (g *Graph[T]) AdjacentOf(from T) []T
- func (g *Graph[T]) GetEdge(from, to T) (float64, bool)
- func (g *Graph[T]) GetEdges() [][]*float64
- func (g *Graph[T]) GetVertices() []T
- func (g *Graph[T]) IndexOf(elem T) int
- func (g *Graph[T]) MakeTree(data T, info uc.Objecter, f tr.NextsFunc[*tn.TreeNode[T]]) (*tr.Tree[*tn.TreeNode[T]], error)
- type WeightFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Graph ¶
Graph represents a graph.
func NewGraph ¶
func NewGraph[T uc.Objecter](vertices []T, f WeightFunc[T]) *Graph[T]
NewGraph creates a new graph with the given vertices.
Parameters:
- vertices: vertices in the graph.
Returns:
- *WeightedGraph: the new graph.
func (*Graph[T]) AdjacentOf ¶
func (g *Graph[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 (*Graph[T]) GetEdge ¶
GetEdge returns the weight of the edge between the given vertices.
Parameters:
- from: the source vertex.
- to: the destination vertex.
Returns:
- float64: the weight of the edge.
- bool: true if the edge exists, otherwise false.
func (*Graph[T]) GetEdges ¶
GetEdges returns the edges in the graph.
Returns:
- [][]*float64: the edges.
func (*Graph[T]) GetVertices ¶
func (g *Graph[T]) GetVertices() []T
GetVertices returns the vertices in the graph.
Returns:
- []T: the vertices.
func (*Graph[T]) IndexOf ¶
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 (*Graph[T]) MakeTree ¶
func (g *Graph[T]) MakeTree(data T, info uc.Objecter, f tr.NextsFunc[*tn.TreeNode[T]]) (*tr.Tree[*tn.TreeNode[T]], error)
MakeTree creates a tree of the graph with the given root.
Parameters:
- data: the data of the root.
- f: the nexts function.
Returns:
- *WeightedGraphTree: the tree of the graph.
- error: an error if the tree creation fails.
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.
Click to show internal directories.
Click to hide internal directories.