treebuilder

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Build

func Build[T any](nodes []T, adapter Adapter[T]) []T

Build constructs a tree structure from a flat slice of nodes using the provided adapter.

func FindNode

func FindNode[T any](roots []T, targetID string, adapter Adapter[T]) (T, bool)

FindNode searches for a node with the given ID in the tree and returns it if found.

func FindNodePath

func FindNodePath[T any](roots []T, targetID string, adapter Adapter[T]) ([]T, bool)

FindNodePath returns the path from root to the target node if found.

Types

type Adapter

type Adapter[T any] struct {
	GetID       func(T) string
	GetParentID func(T) string
	GetChildren func(T) []T
	SetChildren func(*T, []T)
}

Adapter provides functions to access tree node properties.

Jump to

Keyboard shortcuts

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