graph

package
v0.0.0-...-9899634 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config holds configuration values for New to use when contracting a LabeledGraph.

type Graph

type Graph[V comparable] struct {
	// contains filtered or unexported fields
}

Graph is a graph with vertices of type V.

func New

func New[V comparable](opts ...Opt) *Graph[V]

New returns a new LabeledGraph constructed according to the given options.

func (Graph[V]) AddEdge

func (g Graph[V]) AddEdge(u, v V)

AddEdge adds the given edge with the given label to the graph.

func (Graph[V]) AddVertex

func (g Graph[V]) AddVertex(v V)

AddVertex adds the given vertex to the graph.

func (Graph[V]) ContainsEdge

func (g Graph[V]) ContainsEdge(u, v V) bool

ContainsEdge returns whether the given edge is contained in the graph.

func (Graph[V]) ContainsVertex

func (g Graph[V]) ContainsVertex(v V) bool

ContainsVertex returns whether the given vertex is contained in the graph.

func (Graph[V]) Degree

func (g Graph[V]) Degree(u V) (int, bool)

Degree return the number of edges coming into or out of the given vertex and true if the vertex exists in the graph. If the given vertex is not in the graph, an empty iterator is returned.

  • For directed graphs, Degree is the sum of InDegree and OutDegree.
  • For undirected graphs, Degree, InDegree, and OutDegree are all synonymous.

func (Graph[V]) Directed

func (g Graph[V]) Directed() bool

Directed returns whether this graph is directed.

func (Graph[V]) Edges

func (g Graph[V]) Edges() iter.Seq2[V, V]

Edges returns an iterator over all edges in the graph.

func (Graph[V]) InDegree

func (g Graph[V]) InDegree(u V) (int, bool)

InDegree return the number of edges coming into the given vertex and true if the vertex exists in the graph.

func (Graph[V]) InIncidentEdges

func (g Graph[V]) InIncidentEdges(v V) iter.Seq2[V, V]

InIncidentEdges returns an iterator over the edges coming into the given vertex of the graph. If the given vertex is not in the graph, an empty iterator is returned.

  • For directed graphs, this is the set of edges that terminate at the given vertex.
  • For undirected graphs, IncidentEdges, InIncidentEdges, and OutIncidentEdges are all synonymous.

func (Graph[V]) IncidentEdges

func (g Graph[V]) IncidentEdges(v V) iter.Seq2[V, V]

IncidentEdges returns all edges that are incident to the given vertex in the graph. If the given vertex is not in the graph, an empty iterator is returned.

  • For directed graphs, IncidentEdges is the union of InIncidentEdges and OutIncidentEdges.
  • For undirected graphs, IncidentEdges, InIncidentEdges, and OutIncidentEdges are all synonymous.

func (Graph[V]) Neighbors

func (g Graph[V]) Neighbors(v V) iter.Seq[V]

Neighbors is an alias for Successors.

func (Graph[V]) Order

func (g Graph[V]) Order() int

Order returns the number of vertices in the graph.

func (Graph[V]) OutDegree

func (g Graph[V]) OutDegree(u V) (int, bool)

OutDegree return the number of edges coming out of the given vertex and true if the vertex exists in the graph. If no such vertex exists, the zero value and false are returned.

func (Graph[V]) OutIncidentEdges

func (g Graph[V]) OutIncidentEdges(u V) iter.Seq2[V, V]

OutIncidentEdges returns an iterator over the edges coming out of the given vertex of the graph. If the given vertex is not in the graph, an empty iterator is returned.

  • For directed graphs, this is the set of edges that originate at the given vertex.
  • For undirected graphs, IncidentEdges, InIncidentEdges, and OutIncidentEdges are all synonymous.

func (Graph[V]) Predecessors

func (g Graph[V]) Predecessors(v V) iter.Seq[V]

Predecessors returns an iterator over the predecessors of the given vertex in the graph. If the given vertex is not in the graph, an empty iterator is returned.

  • For directed graphs, Predecessors is the set of vertices u, such that (u, v) is an edge in the graph for the given vertex v.
  • For undirected graphs, Predecessors, Successors, and Neighbors are all synonymous.

func (Graph[V]) RemoveEdge

func (g Graph[V]) RemoveEdge(u, v V)

RemoveEdge removes the given edge from the graph.

func (Graph[V]) RemoveVertex

func (g Graph[V]) RemoveVertex(v V)

RemoveVertex removes the vertex and all incident edges from the graph.

func (Graph[V]) Size

func (g Graph[V]) Size() int

Size returns the number of edges in the graph.

func (Graph[V]) Successors

func (g Graph[V]) Successors(u V) iter.Seq[V]

Successors returns an iterator over the successors of the given vertex in the graph. If the given vertex is not in the graph, an empty iterator is returned.

  • For directed graphs, Successors is the set of vertices u, such that (u, v) is an edge in the graph for the given vertex u.
  • For undirected graphs, Predecessors, Successors, and Neighbors are all synonymous.

func (Graph[V]) Vertices

func (g Graph[V]) Vertices() iter.Seq[V]

Vertices returns an iterator over all vertices in the graph.

type Opt

type Opt func(g *Config)

Opt represents a configuration option for constructing a LabeledGraph.

func Directed

func Directed() Opt

Directed is an option that configures New to return a directed graph.

Jump to

Keyboard shortcuts

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