depgraph

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 18, 2024 License: MIT Imports: 3 Imported by: 1

README

Some simple graph sorting algorithms

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
}

func New

func New() *Graph
func (g *Graph) AddLink(name string, from, to any) error

AddLink name here for potential future use

func (*Graph) AddNode

func (g *Graph) AddNode(node any)

func (*Graph) DependOn

func (g *Graph) DependOn(child, parent any) error

DependOn sets a dependency between a child and parent

func (*Graph) DependsOn

func (g *Graph) DependsOn(child, parent any) bool

DependsOn returns true if child depends on parent

func (*Graph) HasDependent

func (g *Graph) HasDependent(parent, child any) bool

HasDependent returns true if child is dependent on parent

func (*Graph) Leaves

func (g *Graph) Leaves() (leaves []any)

Leaves finds all nodes that don't have a dependency

func (*Graph) Nodes

func (g *Graph) Nodes() (nodes []any)

func (*Graph) SortedLayers

func (g *Graph) SortedLayers() (layers [][]any)

SortedLayers returns a slice of graph nodes in topological sort order. That is, if `B` depends on `A`, then `A` is guaranteed to come before `B` in the sorted output. The graph is guaranteed to be cycle-free because cycles are detected while building the graph. Additionally, the output is grouped into "layers", which are guaranteed to not have any dependencyMap within each layer. This is useful, e.g. when building an execution plan for some DAG, in which case each element within each layer could be executed in parallel. If you do not need this layered property, use `Graph.TopoSorted()`, which flattens all elements.

func (*Graph) SortedWithOrder

func (g *Graph) SortedWithOrder() []*TopologyOrder

type TopologyOrder

type TopologyOrder struct {
	Node       any
	Step       string
	SortedStep string
	Level      int
}

Jump to

Keyboard shortcuts

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