Documentation ¶
Overview ¶
The package tree provides resources for building and manipulating a tree data structure, which consists of nodes containing objects. A Node is a container that holds data and references to other nodes, and can have one parent and multiple children. It can store any type of data and has a key/value field for storing additional data.
Index ¶
- func RecursiveDeleteValue(rootNode *Node, key string)
- func RecursiveSetValue_Deepness(rootNode *Node, fieldName string)
- func RecursiveSetValue_HasChildren(rootNode *Node, fieldName string)
- func RecursiveSetValue_Index(rootNode *Node, fieldNameOfIndex, fieldNameOfParentIndex string)
- type Filter
- type Node
- func (o *Node) Adopt(child *Node) error
- func (o *Node) Attach(child *Node, searchFunc SearchFunc, searchCriterion interface{}) error
- func (o *Node) ChildIndex() (int, error)
- func (o *Node) Children() []*Node
- func (o *Node) ChildrenCount() int
- func (o *Node) Deepness() int
- func (o *Node) DeleteValue(key string)
- func (o *Node) GetChild(index int) *Node
- func (o *Node) GetRoot() *Node
- func (o *Node) HasChild(index int) bool
- func (o *Node) HasChildren() bool
- func (o *Node) IsRoot() bool
- func (o *Node) LevelOrderIter() (nodes [][]*Node)
- func (o *Node) NextSibling() (*Node, error)
- func (o *Node) Parent() *Node
- func (o *Node) PostOrderIter() (nodes []*Node)
- func (o *Node) PreOrderIter() (nodes []*Node)
- func (o *Node) PreOrderIterAdvanced(filter Filter) (nodes []*Node)
- func (o *Node) PreviousSibling() (*Node, error)
- func (o *Node) ProcessNodeAndAscendants(processing func(*Node) bool) (stop bool)
- func (o *Node) RecursiveProcessing(preProcessing func(*Node), postProcessing func(*Node))
- func (o *Node) Search(searchFunc SearchFunc, searchCriterion interface{}) (*Node, bool)
- func (o *Node) SetChildren(children []*Node)
- func (o *Node) SetParent(parent *Node)
- func (o *Node) SetValue(key string, value interface{}) *Node
- func (o *Node) SetValues(values map[string]interface{})
- func (o *Node) StoppableRecursiveProcessing(preProcessing func(*Node) bool, postProcessing func(*Node) bool) (stop bool)
- func (o *Node) SwapChildren(childIndex1, childIndex2 int) error
- func (o *Node) Value(key string) (interface{}, bool)
- func (o *Node) ValueBool(key string, def bool) bool
- func (o *Node) ValueExists(key string) bool
- func (o *Node) ValueInt(key string, def int) int
- func (o *Node) ValueInt64(key string, def int64) int64
- func (o *Node) ValueString(key string, def string) string
- func (o *Node) Values() map[string]interface{}
- type SearchFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RecursiveDeleteValue ¶
func RecursiveSetValue_Index ¶
Types ¶
type Node ¶
type Node struct { Object interface{} // contains filtered or unexported fields }
A Node is the fundamental building block of a tree data structure. It is a container that holds data and references to other nodes. A node may have zero or one parent, and it may have multiple children. The root node is the top-level node in a tree, and it is the only node that does not have a parent. A node can store any type of data. It also has a key/value field, which is a map that can be used to store additional data that may be used for processing or rendering.
func NewNodeWithValue ¶
func (*Node) Attach ¶
func (o *Node) Attach(child *Node, searchFunc SearchFunc, searchCriterion interface{}) error
Attach attaches the given child node to the first node found by the searchFunc function using the given searchCriterion value. If no node is found, an error is returned.
func (*Node) ChildIndex ¶
ChildIndex returns the index of the node in it's parent's children list.
func (*Node) ChildrenCount ¶
ChildrenCount returns the number of children Nodes.
func (*Node) DeleteValue ¶
func (*Node) GetChild ¶
GetChild returns the child node at the given index. If the index is out of range, it returns nil.
func (*Node) HasChildren ¶
func (*Node) LevelOrderIter ¶
func (*Node) NextSibling ¶
func (*Node) Parent ¶
Parent returns a pointer of the parent Node. A node can only have one parent. If a node has no parent, it is the root of the tree and Parent() returns nil.
func (*Node) PostOrderIter ¶
func (*Node) PreOrderIter ¶
func (*Node) PreOrderIterAdvanced ¶
func (*Node) PreviousSibling ¶
func (*Node) ProcessNodeAndAscendants ¶
func (*Node) RecursiveProcessing ¶
RecursiveProcessing allows to define a pre and post processing fun
func (*Node) Search ¶
func (o *Node) Search(searchFunc SearchFunc, searchCriterion interface{}) (*Node, bool)