Documentation
¶
Overview ¶
Package graphs implements a simple graph.
Index ¶
- type Graph
- func (g *Graph[T]) AddEdge(a, b T)
- func (g *Graph[T]) AddVertices(t ...T)
- func (g *Graph[T]) ConnectedComponents() [][]T
- func (g *Graph[T]) DeleteEdge(a, b T)
- func (g *Graph[T]) Edges() iter.Seq[[2]T]
- func (g *Graph[T]) HasEdge(a, b T) bool
- func (g *Graph[T]) NumEdges() int
- func (g *Graph[T]) NumVertices() int
- func (g *Graph[T]) Vertices() iter.Seq[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Graph ¶
type Graph[T comparable] struct { // contains filtered or unexported fields }
Graph is a simple graph. It contains a set of vertices and a set of edges, which are pairs of vertices.
func (*Graph[T]) AddEdge ¶
func (g *Graph[T]) AddEdge(a, b T)
AddEdge adds a and b to the vertex set and adds an edge between them. The edge is undirected, meaning that AddEdge(a,b) is equivalent to AddEdge(b,a). If the edge already exists, this is a no-op.
func (*Graph[T]) AddVertices ¶
func (g *Graph[T]) AddVertices(t ...T)
AddVertices adds the given values as vertices. Values that already exist are ignored.
func (*Graph[T]) ConnectedComponents ¶
func (g *Graph[T]) ConnectedComponents() [][]T
ConnectedComponents returns a slice of connected components. In each component, the elements are ordered by order of addition to the graph. The components are ordered by the order of addition of their first elements.
func (*Graph[T]) DeleteEdge ¶
func (g *Graph[T]) DeleteEdge(a, b T)
DeleteEdge removes the edge between a and b, while keeping them in the vertex set.
func (*Graph[T]) NumVertices ¶
NumVertices returns the current number of vertices.