treeconv

package
v2.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListToTree

func ListToTree[L ListItem[T, S, L], T comparable, S TreeNode[L, S]](src []L) []S

ListToTree 列表转树

Types

type ListItem

type ListItem[T comparable, S TreeNode[M, S], M any] interface {
	GetID() T       // 获取 ID
	GetParentID() T // 获取父 ID
}

ListItem 列表项接口 T 用于接收数据源的唯一标识,需要可比较 S 是需要转换的目标数据结构 M 是ListItem数据源本身

type TreeNode

type TreeNode[M any, S any] interface {
	PrepareChildren(n int)                          // 预分配子节点
	AddChild(Node S)                                // 添加子节点
	GetLastChild() (S, bool)                        // 获取最后一个子节点
	ToTreeNode(src M, level int, parentNode ...S) S // 转换成树节点
}

TreeNode 树节点接口 M 是数据源,将数据换转传承TreeNode S 是树节点本身

Jump to

Keyboard shortcuts

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