Documentation ¶
Index ¶
- Variables
- func ValuesAsList[T any](tree *Tree[T]) []T
- type Path
- type Tree
- func (tree *Tree[T]) Get(treePath ...string) (value T, err error)
- func (n *Tree[T]) IsLeaf() bool
- func (tree *Tree[T]) Leaves() iter.Seq2[Path, T]
- func (tree *Tree[T]) NumLeaves() int
- func (tree *Tree[T]) OrderedLeaves() iter.Seq2[Path, T]
- func (tree *Tree[T]) Set(treePath Path, value T) error
- func (tree *Tree[T]) String() string
Constants ¶
This section is empty.
Variables ¶
var DefaultTreePath = []string{"#root"}
DefaultTreePath is used whenever an empty treePath is given.
Functions ¶
func ValuesAsList ¶
ValuesAsList extracts the leaf values of Tree into a list.
It's generated in alphabetical order -- see OrderedLeaves to see or generate the order.
Types ¶
type Tree ¶
type Tree[T any] struct { // Value is set for leaf nodes only. Value T // Map is set for non-leaf nodes (and nil in leaf nodes). Map map[string]*Tree[T] }
Tree represent both a root of a tree, and a tree node.
It can either be a Value or a Map of its children -- but not both.
func FromValuesAndTree ¶
FromValuesAndTree creates a Tree[T1] with the given values, but borrowing the structure from the given tree (but ignoring the tree's values).
func (*Tree[T]) Get ¶
Get value in treePath. It returns an error if such a leaf node doesn't exist.
Empty values in treePath are not used.
func (*Tree[T]) Leaves ¶
Leaves returns an iterator that goes over all the leaf nodes of the Tree. The key is a Path, and value is T.
func (*Tree[T]) OrderedLeaves ¶
OrderedLeaves returns an iterator that goes over all the leaf nodes of the Tree in alphabetical order of the tree nodes (depth-first).
The key is a Path, and value is T.