graph

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FanIn

func FanIn(g *Graph) map[string]int

FanIn returns the in-degree for every node in the graph.

func FanOut

func FanOut(g *Graph) map[string]int

FanOut returns the out-degree for every node in the graph.

func FindSCCs

func FindSCCs(g *Graph) [][]string

FindSCCs returns strongly connected components with size > 1 using Tarjan's algorithm. Each SCC is sorted alphabetically, and the list of SCCs is sorted by first element for deterministic output.

Types

type Graph

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

Graph is a directed graph with string-labeled nodes.

func NewGraph

func NewGraph() *Graph

NewGraph creates an empty directed graph.

func (*Graph) AddEdge

func (g *Graph) AddEdge(from, to string)

AddEdge adds a directed edge from -> to, creating both nodes if absent.

func (*Graph) AddNode

func (g *Graph) AddNode(name string)

AddNode adds a node to the graph. Duplicate calls are safe.

func (*Graph) Neighbors

func (g *Graph) Neighbors(node string) []string

Neighbors returns the sorted successors of a node.

func (*Graph) Nodes

func (g *Graph) Nodes() []string

Nodes returns all node names sorted alphabetically.

Jump to

Keyboard shortcuts

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