graph

package
v0.22.1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Graph

type Graph[T Node] struct {
	// contains filtered or unexported fields
}

Graph is a directed, cyclic, unweighted graph.

func New

func New[T Node]() *Graph[T]

func (*Graph[T]) DeleteFunc added in v0.17.0

func (g *Graph[T]) DeleteFunc(del func(T) bool)

DeleteFunc deletes all nodes for which del returns true. If removing a node causes the graph to change, the deletion is recursive, removing all nodes that are no longer referenced.

func (*Graph[T]) Edges

func (g *Graph[T]) Edges() map[string]map[string]bool

Edges returns all of the graph's edges.

func (*Graph[T]) InsertGraph

func (g *Graph[T]) InsertGraph(other *Graph[T])

InsertGraph merges other into g.

func (*Graph[T]) InsertTree

func (g *Graph[T]) InsertTree(nodes ...T)

InsertTree inserts nodes of a tree, ordered root first, leaf last.

func (*Graph[T]) Nodes

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

Nodes returns all of the graph's nodes.

func (*Graph[T]) Roots

func (g *Graph[T]) Roots() []T

func (*Graph[T]) String

func (g *Graph[T]) String() string

String returns a string describing the graph.

func (*Graph[T]) Subgraph

func (g *Graph[T]) Subgraph(rootID string) *Graph[T]

Subgraph returns a graph including all nodes and edges reachable from the specified root.

type Node

type Node interface {
	// ID uniquely identifies this node. Any node with the same ID is expected to
	// contain the exact same data.
	ID() string
}

Jump to

Keyboard shortcuts

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