tree

package
v0.0.0-...-e50112c Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterNodeDataDecoder

func RegisterNodeDataDecoder(typ string, f func(bytes []byte) (interface{}, error))

Types

type EachOrder

type EachOrder int
const (
	OrderPre  EachOrder = 1 // 前序遍历,先遍历根节点,然后再遍历子节点
	OrderPost EachOrder = 2 // 后序遍历,先遍历子节点,然后再遍历根节点
)

func (EachOrder) String

func (i EachOrder) String() string

type Node

type Node struct {
	// contains filtered or unexported fields
}

func (*Node) AddChild

func (this *Node) AddChild(id string, typ string, data interface{}) (added *Node, err error)

func (*Node) AddChildData

func (this *Node) AddChildData(data ...NodeData) (added []*Node, err error)

func (*Node) Children

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

func (*Node) Data

func (this *Node) Data() interface{}

func (*Node) Each

func (this *Node) Each(order EachOrder, f func(node *Node, depth int) bool, maxDepth ...int)

遍历节点及其所有子孙节点。

order: 排序方式。 PreOrder=前序遍历; PostOrder=后序遍历。
f: 回调函数,如果 f 返回 false,则会中止遍历。
   depth: 当前遍历深度,从 0 开始累加。
maxDepth: 最大遍历深度。

func (*Node) Id

func (this *Node) Id() string

func (*Node) MustAddChild

func (this *Node) MustAddChild(id string, typ string, data interface{}) (added *Node)

func (*Node) Parent

func (this *Node) Parent() *Node

func (*Node) SetData

func (this *Node) SetData(typ string, data interface{}) *Node

func (*Node) Type

func (this *Node) Type() string

type NodeData

type NodeData struct {
	Id   string
	Type string
	Data interface{}
}

type Tree

type Tree struct {
	Name string `json:"name,omitempty"`
	// contains filtered or unexported fields
}

func (*Tree) AddNode

func (this *Tree) AddNode(pid, id string, typ string, data interface{}) (added *Node, err error)

func (*Tree) Each

func (this *Tree) Each(order EachOrder, f func(node *Node, depth int) bool, maxDepth ...int)

遍历节点及其所有子孙节点。

order: 排序方式。 PreOrder=前序遍历; PostOrder=后序遍历。
f: 回调函数,如果 f 返回 false,则会中止遍历。
   depth: 当前遍历深度,从 0 开始累加。
maxDepth: 最大遍历深度。

func (*Tree) GetNode

func (this *Tree) GetNode(id string) (node *Node)

func (*Tree) MustAddNode

func (this *Tree) MustAddNode(pid, id string, typ string, data interface{}) (added *Node)

func (*Tree) Root

func (this *Tree) Root() *Node

func (*Tree) Update

func (this *Tree) Update()

Jump to

Keyboard shortcuts

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