tree

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2023 License: MIT Imports: 1 Imported by: 2

README

Usage

import (
    "github.com/tpfeiffer67/tree"
)

License

This repository is licensed under the MIT License. See the LICENSE file for more information.

Author

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func RecursiveDeleteValue

func RecursiveDeleteValue(rootNode *Node, key string)

func RecursiveSetValue_Deepness

func RecursiveSetValue_Deepness(rootNode *Node, fieldName string)

func RecursiveSetValue_HasChildren

func RecursiveSetValue_HasChildren(rootNode *Node, fieldName string)

func RecursiveSetValue_Index

func RecursiveSetValue_Index(rootNode *Node, fieldNameOfIndex, fieldNameOfParentIndex string)

Types

type Filter

type Filter func(*Node) bool

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 NewNode

func NewNode() *Node

func NewNodeWithValue

func NewNodeWithValue(key string, value interface{}) *Node

func (*Node) Adopt

func (o *Node) Adopt(child *Node) error

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

func (o *Node) ChildIndex() (int, error)

ChildIndex returns the index of the node in it's parent's children list.

func (*Node) Children

func (o *Node) Children() []*Node

Children return a slice of the children Nodes.

func (*Node) ChildrenCount

func (o *Node) ChildrenCount() int

ChildrenCount returns the number of children Nodes.

func (*Node) Deepness

func (o *Node) Deepness() int

func (*Node) DeleteValue

func (o *Node) DeleteValue(key string)

func (*Node) GetChild

func (o *Node) GetChild(index int) *Node

GetChild returns the child node at the given index. If the index is out of range, it returns nil.

func (*Node) GetRoot

func (o *Node) GetRoot() *Node

func (*Node) HasChild

func (o *Node) HasChild(index int) bool

func (*Node) HasChildren

func (o *Node) HasChildren() bool

func (*Node) IsRoot

func (o *Node) IsRoot() bool

func (*Node) LevelOrderIter

func (o *Node) LevelOrderIter() (nodes [][]*Node)

func (*Node) NextSibling

func (o *Node) NextSibling() (*Node, error)

func (*Node) Parent

func (o *Node) Parent() *Node

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 (o *Node) PostOrderIter() (nodes []*Node)

func (*Node) PreOrderIter

func (o *Node) PreOrderIter() (nodes []*Node)

func (*Node) PreOrderIterAdvanced

func (o *Node) PreOrderIterAdvanced(filter Filter) (nodes []*Node)

func (*Node) PreviousSibling

func (o *Node) PreviousSibling() (*Node, error)

func (*Node) ProcessNodeAndAscendants

func (o *Node) ProcessNodeAndAscendants(processing func(*Node) bool) (stop bool)

func (*Node) RecursiveProcessing

func (o *Node) RecursiveProcessing(preProcessing func(*Node), postProcessing func(*Node))

RecursiveProcessing allows to define a pre and post processing fun

func (*Node) Search

func (o *Node) Search(searchFunc SearchFunc, searchCriterion interface{}) (*Node, bool)

func (*Node) SetChildren

func (o *Node) SetChildren(children []*Node)

func (*Node) SetParent

func (o *Node) SetParent(parent *Node)

SetParent sets or changes the parent Node.

func (*Node) SetValue

func (o *Node) SetValue(key string, value interface{}) *Node

func (*Node) SetValues

func (o *Node) SetValues(values map[string]interface{})

func (*Node) StoppableRecursiveProcessing

func (o *Node) StoppableRecursiveProcessing(preProcessing func(*Node) bool, postProcessing func(*Node) bool) (stop bool)

func (*Node) SwapChildren

func (o *Node) SwapChildren(childIndex1, childIndex2 int) error

func (*Node) Value

func (o *Node) Value(key string) (interface{}, bool)

func (*Node) ValueBool

func (o *Node) ValueBool(key string, def bool) bool

func (*Node) ValueExists

func (o *Node) ValueExists(key string) bool

func (*Node) ValueInt

func (o *Node) ValueInt(key string, def int) int

func (*Node) ValueInt64

func (o *Node) ValueInt64(key string, def int64) int64

func (*Node) ValueString

func (o *Node) ValueString(key string, def string) string

func (*Node) Values

func (o *Node) Values() map[string]interface{}

type SearchFunc

type SearchFunc func(*Node, interface{}) bool

Directories

Path Synopsis
exp
imp

Jump to

Keyboard shortcuts

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