graph

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2025 License: MIT Imports: 0 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 struct {
	// contains filtered or unexported fields
}

Graph is a directed graph for use with the DAG policy. Graph only represents edge relationships. There is no notion of node existence.

func NewGraph

func NewGraph() Graph

func (Graph) AddEdge

func (d Graph) AddEdge(node1, node2 string)

AddEdge adds an edge between node1 and node2. Edges are directional, so this will add node2 to node1's neighbour set, but will not add node1 to node2's neighbour set. Self-connections are allowed and will be detected as a cycle. This function is idempotent.

func (Graph) HasCycle

func (d Graph) HasCycle() ([]string, bool)

HasCycle searches for cycles in the graph. If one or more cycles exists, one of the cycles is returned at random. If no cycle exists, returns nil, false. Returned cycles are in the form of a list of nodes, where subsequent nodes are connected in the graph, and the last element is connected to the first element.

func (Graph) Neighbours

func (d Graph) Neighbours(node string) map[string]struct{}

Neighbours returns the neighbours of a node. A neighbour relationship is directional. If only the edge a->b exists, then Neighbours(a) will include b, but Neighbours(b) will not include a.

Jump to

Keyboard shortcuts

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