treebuilder

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2025 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 converts a flat slice of nodes into a tree structure using the provided adapter. Time complexity: O(n), Space complexity: O(n).

func FindNode

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

FindNode finds a node by Id in the tree structure built with Adapter.

func FindNodePath

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

Types

type Adapter

type Adapter[T any] struct {
	GetId       func(T) string // extracts the unique identifier
	GetParentId func(T) string // extracts the parent identifier
	GetChildren func(T) []T    // extracts the children slice
	SetChildren func(*T, []T)  // sets the children slice (requires pointer)
}

Adapter defines the adapter for building trees from arbitrary data.

Jump to

Keyboard shortcuts

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