graph

package
v0.3.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 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 struct {
	What string
	// contains filtered or unexported fields
}

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

func (*CyclicError) Error

func (c *CyclicError) Error() string

Error implements error interface

type Graph

type Graph struct {
	Nodes map[string]*Node

	Root *Node
	// contains filtered or unexported fields
}

func NewGraph

func NewGraph(root *Node) *Graph

func NewGraphOf

func NewGraphOf(root *Node, item string) *Graph

func (*Graph) AddEdge

func (g *Graph) 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) Clone

func (g *Graph) Clone() *Graph

Clone returns a cloned graph

func (*Graph) GetNextLeaf

func (g *Graph) GetNextLeaf(start *Node) *Node

GetNextLeaf returns the next leaf in the graph from node start

func (*Graph) InsertNodeAt

func (g *Graph) InsertNodeAt(parentID string, id string, data interface{}) (*Node, error)

InsertNodeAt inserts a new node at the given parent position

func (*Graph) RemoveNode

func (g *Graph) RemoveNode(id string) error

RemoveNode removes a node with no children in the graph

type Node

type Node struct {
	ID   string
	Data interface{}

	Parents []*Node
	Childs  []*Node
}

Node is a node in a graph

func NewNode

func NewNode(id string, data interface{}) *Node

Jump to

Keyboard shortcuts

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