dag

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrVertexAlreadyExists

type ErrVertexAlreadyExists struct {
	Key string
}

func (ErrVertexAlreadyExists) Error

func (err ErrVertexAlreadyExists) Error() string

type ErrVertexNotFoundForEdge

type ErrVertexNotFoundForEdge struct {
	Source  string
	Missing string
	Type    string
}

func (ErrVertexNotFoundForEdge) Error

func (err ErrVertexNotFoundForEdge) Error() string

type Graph

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

func NewGraph

func NewGraph[T Graphable](vertices []T) (*Graph, error)

func (*Graph) AddEdge

func (g *Graph) AddEdge(from string, to string) error

AddEdge adds an edge between 2 vertices in the graph. 'from' is the parent, and 'to' is the child. It fills in both sides, so we'll add a child to the parent 'from' pointing at 'to'. And we'll add a parent to the child 'to' pointing at 'from'. TODO: Check for cycles here to ensure its acylic.

func (*Graph) AddVertex

func (g *Graph) AddVertex(key string) error

func (*Graph) GetVertex

func (g *Graph) GetVertex(key string) *Vertex

func (*Graph) Leaves

func (g *Graph) Leaves() []*Vertex

func (*Graph) RemoveVertex

func (g *Graph) RemoveVertex(key string)

func (*Graph) Roots

func (g *Graph) Roots() []*Vertex

func (*Graph) TopologicalKeysFromLeaves

func (g *Graph) TopologicalKeysFromLeaves() ([]string, error)

func (*Graph) TopologicalKeysFromRoots

func (g *Graph) TopologicalKeysFromRoots() ([]string, error)

type Graphable

type Graphable interface {
	GetKey() string
	GetChildren() []string
	GetParents() []string
}

type Vertex

type Vertex struct {
	Key      string
	Children Vertices
	Parents  Vertices
}

func (*Vertex) AddChild

func (v *Vertex) AddChild(key string, child *Vertex)

func (*Vertex) AddParent

func (v *Vertex) AddParent(key string, parent *Vertex)

func (*Vertex) HasChild

func (v *Vertex) HasChild(key string) bool

func (*Vertex) HasParent

func (v *Vertex) HasParent(key string) bool

func (*Vertex) RemoveChildIfExists

func (v *Vertex) RemoveChildIfExists(key string)

func (*Vertex) RemoveParentIfExists

func (v *Vertex) RemoveParentIfExists(key string)

type Vertices

type Vertices map[string]*Vertex

Jump to

Keyboard shortcuts

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