treeutils

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2023 License: Apache-2.0 Imports: 1 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FullName

func FullName[T Key](id T, nodes []*TNode[T]) (Name []string)

FullName 在树中找到全名 @Param id 带查找全名的主键 @Param nodes id 节点所在的节点列表 @Return Name 返回 指定id的全名列表,名称按顺序排序

func GetChildIds

func GetChildIds[T Key, L Empty[T]](all []L, pid ...T) (childIds []T)

GetChildIds 查询 pid 及其 pid的子id列表 @Param all 节点id列表 @Param pid 待查询的 父节点列表 @Return childIds 返回 pid 及其 pid的子节点id

Types

type Empty

type Empty[T Key] interface {
	// GetId 获取 Empty 自生ID
	GetId() T
	// GetPid 获取 Empty 的父ID
	GetPid() T
	// GetName 获取 获取 Empty Name
	GetName() string
}

Empty 实现接口 通过获取一个父id和获取一个当前id

type Key

type Key interface {
	int | string
}

Key 数据库 key 类型约束

type TNode

type TNode[T Key] struct {
	Empty[T] `json:"empty"`
	Child    []*TNode[T] `json:"children"`
}

TNode 树节点

func ChildTree

func ChildTree[T Key, L Empty[T]](id T, list []L) (tree []*TNode[T])

ChildTree 获取 id 下的子树 @Param id 需要查询的节点主键id @Param list 实现 Empty[T] 的切片数据 @Return tree 返回 指定 id 的节点及其子节点

func Tree

func Tree[T Key, L Empty[T]](id T, list []L) (tree []*TNode[T])

Tree 查找到当前id及其子节点树 @Param id 需要查询的节点主键id @Param list 实现 Empty[T] 的切片数据 @Return tree 返回 指定 id 的节点及其子节点

Jump to

Keyboard shortcuts

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