Documentation ¶
Overview ¶
Package tree provides functionality for working with tree-like data structures.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Marshal ¶
func Marshal[T comparable](root NodeMarshaler[T]) ([]byte, error)
Marshal serializes a tree structure into a byte slice.
Types ¶
type Node ¶
type Node[T comparable] interface { // String returns the node's information as a string. String() string // Parent returns the parent node or zero value if it's the root. Parent() T // NumChild returns the number of child nodes. NumChild() int // GetChildByIndex returns the child node at the given index. // It returns the zero value of T if the index is out of range. GetChildByIndex(i int) T }
Node represents a generic printable node in a tree structure.
type NodeMarshaler ¶
type NodeMarshaler[T comparable] interface { Node[T] // Marshal serializes the node into a byte slice. Marshal() ([]byte, error) }
NodeMarshaler extends Node with marshaling capability.
Click to show internal directories.
Click to hide internal directories.