graph

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 0 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package graph represents directed graphs and detects cycles in them.

Nothing here knows what the nodes stand for: a caller exposes its own structure through the Graph interface by numbering its nodes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAcyclic

func IsAcyclic(g Graph) (bool, []int)

IsAcyclic reports whether the graph is free of cycles, returning the nodes of the cycle it finds in traversal order, closing node repeated last.

func IsAcyclicFrom

func IsAcyclicFrom(g Graph, u int) (bool, []int)

IsAcyclicFrom reports on the part of the graph reachable from node u. Adding a node to an acyclic graph only closes cycles running through it, so a caller checking each node as it is added never walks the whole graph.

Types

type Graph

type Graph interface {
	// Order returns the number of nodes in the graph.
	Order() int

	// EdgesFrom returns the nodes that node u has an outgoing edge to.
	EdgesFrom(u int) []int
}

Graph is a directed graph whose nodes are the integers in the range [0, Order).

Jump to

Keyboard shortcuts

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