graph

package
v0.6.4-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CyclicError

type CyclicError[T comparable] struct {
	What string
	// contains filtered or unexported fields
}

CyclicError is the type that is returned if a cyclic edge would be inserted

func (*CyclicError[T]) Error

func (c *CyclicError[T]) Error() string

Error implements error interface

type Graph

type Graph[T comparable] struct {
	Nodes map[string]*Node[T]
	Root  *Node[T]
	// contains filtered or unexported fields
}

func NewGraph

func NewGraph[T comparable](root *Node[T]) *Graph[T]

func NewGraphOf

func NewGraphOf[T comparable](root *Node[T], item string) *Graph[T]

func (*Graph[T]) AddChild added in v0.3.4

func (g *Graph[T]) AddChild(parentID string, childID string) error

func (*Graph[T]) AddEdge

func (g *Graph[T]) AddEdge(fromID string, toID string) error

AddEdge adds a new edge from a node to a node and returns an error if it would result in a cyclic graph

func (*Graph[T]) Clone

func (g *Graph[T]) Clone() *Graph[T]

Clone returns a cloned graph

func (*Graph[T]) GetNextLeaf

func (g *Graph[T]) GetNextLeaf(start *Node[T]) *Node[T]

GetNextLeaf returns the next leaf in the graph from node start

func (*Graph[T]) InsertNodeAt

func (g *Graph[T]) InsertNodeAt(parentID string, id string, data T) (*Node[T], error)

InsertNodeAt inserts a new node at the given parent position

func (*Graph[T]) NextFromTop added in v0.3.4

func (g *Graph[T]) NextFromTop() *Node[T]

func (*Graph[T]) RemoveNode

func (g *Graph[T]) RemoveNode(id string) error

RemoveNode removes a node with no children in the graph

func (*Graph[T]) RemoveSubGraph added in v0.3.4

func (g *Graph[T]) RemoveSubGraph(id string) error

type Node

type Node[T comparable] struct {
	ID   string
	Data T

	Parents []*Node[T]
	Childs  []*Node[T]

	Done bool
}

Node is a node in a graph

func NewNode

func NewNode[T comparable](id string, data T) *Node[T]

Jump to

Keyboard shortcuts

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