Documentation ¶
Overview ¶
Package tree provides tree structure related types and utilities.
Index ¶
- Variables
- type BasicNode
- func (n *BasicNode[K, V]) Add(key K, value V) *BasicNode[K, V]
- func (n *BasicNode[K, V]) Child(key K) *BasicNode[K, V]
- func (n *BasicNode[K, V]) Children() map[K]*BasicNode[K, V]
- func (n *BasicNode[K, V]) Key() (key K)
- func (n *BasicNode[K, V]) Len() (total int)
- func (n *BasicNode[K, V]) Parent() *BasicNode[K, V]
- func (n *BasicNode[K, V]) Path() []K
- func (n *BasicNode[K, V]) PathRev() []K
- func (n *BasicNode[K, V]) Remove(key K) (child *BasicNode[K, V], removed bool)
- func (n *BasicNode[K, V]) SetParent(parent *BasicNode[K, V])
- func (n *BasicNode[K, V]) SetValue(value V)
- func (n *BasicNode[K, V]) Value() (value V)
- func (n *BasicNode[K, V]) Walk(fn NodeWalker[K, V]) error
- func (n *BasicNode[K, V]) WalkRev(fn NodeWalker[K, V]) error
- type NodeWalker
Constants ¶
This section is empty.
Variables ¶
var ErrSkipSubtree = errors.New("skip subtree")
ErrSkipSubtree is a sentinel value that can be returned by a NodeWalker to skip the remainder of a subtree. This error halts iteration of that subtree at the first handling parent.
Functions ¶
This section is empty.
Types ¶
type BasicNode ¶
type BasicNode[K constraints.Ordered, V comparable] struct { // contains filtered or unexported fields }
BasicNode is a basic, arbitrarily-ordered, non-balancing, key/value tree.
func NewBasicNode ¶
func NewBasicNode[K constraints.Ordered, V comparable]( key K, value V, ) *BasicNode[K, V]
NewBasicNode creates a new BasicNode.
func (*BasicNode[K, V]) Add ¶
Add adds a new child with the given key and value to this node, returning the new node.
func (*BasicNode[K, V]) Child ¶
Child returns the child of with the given key, if one exists. If no child with the given key is found, nil is returned.
func (*BasicNode[K, V]) Path ¶
func (n *BasicNode[K, V]) Path() []K
Path returns all keys in the path from the root node to this node.
func (*BasicNode[K, V]) PathRev ¶
func (n *BasicNode[K, V]) PathRev() []K
PathRev returns all keys in the path from this node to the root.
func (*BasicNode[K, V]) SetValue ¶
func (n *BasicNode[K, V]) SetValue(value V)
SetValue sets the node's value.
func (*BasicNode[K, V]) Value ¶
func (n *BasicNode[K, V]) Value() (value V)
Value returns the node's value.
func (*BasicNode[K, V]) Walk ¶
func (n *BasicNode[K, V]) Walk(fn NodeWalker[K, V]) error
Walk walks through the tree depth-first.
func (*BasicNode[K, V]) WalkRev ¶
func (n *BasicNode[K, V]) WalkRev(fn NodeWalker[K, V]) error
WalkRev walks through the tree depth-first in reverse.
type NodeWalker ¶
type NodeWalker[K constraints.Ordered, V comparable] func(node *BasicNode[K, V]) error
A NodeWalker is a function that controls how nodes are walked.