pdag

package
v3.228.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Overview

Package pdag provides facilities for constructing a DAG and the traversing it efficiently in parallel.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DAG

type DAG[T any] struct {
	// contains filtered or unexported fields
}

func New added in v3.211.0

func New[T any]() *DAG[T]

func (*DAG[T]) Drain added in v3.211.0

func (g *DAG[T]) Drain(ctx context.Context) iter.Seq2[T, Done]

Drain nodes from the dag. Nodes will always come after their dependents.

Any returned Done func **must** be called. Failing to do so may cause other iterators to block indefinitely or leak memory.

The returned iterator may be called in parallel. When called in parallel, the iterator may block when no nodes are available. The returned iterator will not return until the entire graph has been walked.

Drain will stop the iterator when the passed in ctx is canceled. If the caller is concerned about the context being canceled, they **must** check ctx.Err() to determine if Drain finished.

func (*DAG[T]) NewEdge

func (g *DAG[T]) NewEdge(from, to Node) error

NewEdge creates a new edge FROM -> TO, ensuring that FROM comes before TO in a traversal of g.

func (*DAG[T]) NewNode

func (g *DAG[T]) NewNode(v T) (Node, Done)

Create a new node. The node will not be processed until Done is called, and all nodes with edges leading to it have been processed.

func (*DAG[T]) Walk

func (g *DAG[T]) Walk(ctx context.Context, process func(context.Context, T) error, options ...WalkOption) error

Walk the DAG in parallel, blocking until all nodes have been processed or an error is returned.

[Node]s added during a Walk will be observed during the walk.

type Done added in v3.211.0

type Done = func()

Calling marks a process as done.

type ErrorCycle

type ErrorCycle[T any] struct {
	Cycle []T
}

func (ErrorCycle[T]) Error

func (err ErrorCycle[T]) Error() string

type ErrorReentrant added in v3.211.0

type ErrorReentrant struct{}

ErrorReentrant indicates that [NewEdge] attempted to create a "from->to" connection where "to" was already walked (or currently being walked) and "from" was not yet walked (or currently is being walked). This would violate the [DAG]s traversal guarantees, since it guarantees that nodes will only be seen after all of their from edges have been seen.

func (ErrorReentrant) Error added in v3.211.0

func (err ErrorReentrant) Error() string

type Node

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

Node is a reference to a node in a DAG.

The only way to create a Node is with DAG.NewNode, and the Node is only valid in the context of the graph it was created in.

type WalkOption

type WalkOption interface {
	// contains filtered or unexported methods
}

func MaxProcs

func MaxProcs(i int) WalkOption

MaxProcs limits the number of concurrent work threads in a DAG.Walk call.

i is ignored if it is less then 1.

Jump to

Keyboard shortcuts

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