Help us shape the future of Go! Take the 2026 Go Developer Survey

dag

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CycleError

type CycleError[T cmp.Ordered] struct {
	Cycle []T
}

func AsCycleError

func AsCycleError[T cmp.Ordered](err error) *CycleError[T]

AsCycleError returns the (potentially wrapped) CycleError, or nil if it is not a CycleError.

func (*CycleError[T]) Error

func (e *CycleError[T]) Error() string

type DirectedAcyclicGraph

type DirectedAcyclicGraph[T cmp.Ordered] struct {
	// Vertices stores the nodes in the graph
	Vertices map[T]*Vertex[T]
}

DirectedAcyclicGraph represents a directed acyclic graph

func NewDirectedAcyclicGraph

func NewDirectedAcyclicGraph[T cmp.Ordered]() *DirectedAcyclicGraph[T]

NewDirectedAcyclicGraph creates a new directed acyclic graph.

func (*DirectedAcyclicGraph[T]) AddDependencies

func (d *DirectedAcyclicGraph[T]) AddDependencies(from T, dependencies []T) error

AddDependencies adds a set of dependencies to the "from" vertex. This indicates that all the vertexes in "dependencies" must occur before "from".

func (*DirectedAcyclicGraph[T]) AddVertex

func (d *DirectedAcyclicGraph[T]) AddVertex(id T, order int) error

AddVertex adds a new node to the graph.

func (*DirectedAcyclicGraph[T]) TopologicalSort

func (d *DirectedAcyclicGraph[T]) TopologicalSort() ([]T, error)

TopologicalSort returns the vertexes of the graph, respecting topological ordering first, and preserving order of nodes within each "depth" of the topological ordering.

type Vertex

type Vertex[T cmp.Ordered] struct {
	// ID is a unique identifier for the node
	ID T
	// Order records the original order, and is used to preserve the original user-provided ordering as far as possible.
	Order int
	// DependsOn stores the IDs of the nodes that this node depends on.
	// If we depend on another vertex, we must appear after that vertex in the topological sort.
	DependsOn map[T]struct{}
}

Vertex represents a node/vertex in a directed acyclic graph.

func (Vertex[T]) String

func (v Vertex[T]) String() string

Jump to

Keyboard shortcuts

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