tree

package
v0.0.0-...-293e5de Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: Apache-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 DepthFirstWalker

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

DepthFirstWalker implements stateful depth-first Tree traversal.

func NewDepthFirstWalker

func NewDepthFirstWalker(reader Reader, visitor NodeVisitor) *DepthFirstWalker

func NewDepthFirstWalkerWithConditions

func NewDepthFirstWalkerWithConditions(reader Reader, visitor NodeVisitor, conditions WalkConditions) *DepthFirstWalker

func (*DepthFirstWalker) Visited

func (w *DepthFirstWalker) Visited(n node.Node) bool

func (*DepthFirstWalker) Walk

func (w *DepthFirstWalker) Walk(from node.Node) (node.Node, error)

func (*DepthFirstWalker) WalkAll

func (w *DepthFirstWalker) WalkAll() error

type NodeVisitor

type NodeVisitor func(node.Node) error

type Reader

type Reader interface {
	Node(id node.ID) node.Node
	Nodes() node.Nodes
	Children(n node.Node) node.Nodes
	Parent(n node.Node) node.Node
	Roots() node.Nodes
}

type Tree

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

Tree represents a simple Tree data structure.

func NewTree

func NewTree() *Tree

NewTree returns an instance of a Tree.

func (*Tree) AddChild

func (t *Tree) AddChild(from, to node.Node) error

AddChild adds a node to the Tree under the given parent.

func (*Tree) AddRoot

func (t *Tree) AddRoot(n node.Node) error

AddRoot adds a node to the Tree (with no parent).

func (*Tree) Children

func (t *Tree) Children(n node.Node) node.Nodes

Children returns all children of the given node.

func (*Tree) Copy

func (t *Tree) Copy() *Tree

func (*Tree) HasNode

func (t *Tree) HasNode(id node.ID) bool

HasNode indicates is the given node ID exists in the Tree.

func (*Tree) Length

func (t *Tree) Length() int

func (*Tree) Node

func (t *Tree) Node(id node.ID) node.Node

Node returns a node object for the given ID.

func (*Tree) Nodes

func (t *Tree) Nodes() node.Nodes

Nodes returns all nodes in the Tree.

func (*Tree) Parent

func (t *Tree) Parent(n node.Node) node.Node

Parent returns the parent of the given node (or nil if it is a root)

func (*Tree) RemoveNode

func (t *Tree) RemoveNode(n node.Node) (node.Nodes, error)

RemoveNode deletes the node from the Tree and returns the removed node.

func (*Tree) Replace

func (t *Tree) Replace(old node.Node, new node.Node) error

Replace takes the given old node and replaces it with the given new one.

func (*Tree) Roots

func (t *Tree) Roots() node.Nodes

Roots is all of the nodes with no parents.

type WalkConditions

type WalkConditions struct {
	// Return true when the walker should stop traversing (before visiting current node)
	ShouldTerminate func(node.Node) bool

	// Whether we should visit the current node. Note: this will continue down the same traversal
	// path, only "skipping" over a single node (but still potentially visiting children later)
	// Return true to visit the current node.
	ShouldVisit func(node.Node) bool

	// Whether we should consider children of this node to be included in the traversal path.
	// Return true to traverse children of this node.
	ShouldContinueBranch func(node.Node) bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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