Documentation
¶
Index ¶
- type DepthFirstWalker
- type NodeVisitor
- type Reader
- type Tree
- func (t *Tree) AddChild(from, to node.Node) error
- func (t *Tree) AddRoot(n node.Node) error
- func (t *Tree) Children(n node.Node) node.Nodes
- func (t *Tree) Copy() *Tree
- func (t *Tree) HasNode(id node.ID) bool
- func (t *Tree) Length() int
- func (t *Tree) Node(id node.ID) node.Node
- func (t *Tree) Nodes() node.Nodes
- func (t *Tree) Parent(n node.Node) node.Node
- func (t *Tree) RemoveNode(n node.Node) (node.Nodes, error)
- func (t *Tree) Replace(old node.Node, newNode node.Node) error
- func (t *Tree) Roots() node.Nodes
- type WalkConditions
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) WalkAll ¶
func (w *DepthFirstWalker) WalkAll() error
type NodeVisitor ¶
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
}
Reader is read-only access to a Tree. Nodes returned from it are shared with copies of the Tree and must not be modified.
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree represents a simple Tree data structure.
Nodes are shared between a Tree and its copies, so a node must never be mutated once it is in a Tree. To change a node, Replace it with a new one.
func (*Tree) AddChild ¶
AddChild adds the child node (to) under the parent node (from), adding either to the Tree if missing (a missing parent becomes a root). The stored objects for both nodes are replaced with the ones given. If the child already has a different parent it is moved, along with its subtree, to the new parent. Every node has at most one parent, and an edge that would create a cycle is rejected.
func (*Tree) Copy ¶
Copy returns a structural copy of the Tree. Nodes are shared with the original (see Tree).
func (*Tree) RemoveNode ¶
RemoveNode deletes the node from the Tree and returns the removed node.
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
}