haive.core.common.structures.tree_leaf.base¶

Base tree node classes with advanced generic support.

Classes¶

Leaf

Leaf node - has content but no children.

Tree

Tree node - has content and children.

TreeNode

Abstract base class for all tree nodes.

Module Contents¶

class haive.core.common.structures.tree_leaf.base.Leaf[source]¶

Bases: TreeNode[haive.core.common.structures.tree_leaf.generics.ContentT, haive.core.common.structures.tree_leaf.generics.ResultT], Generic[haive.core.common.structures.tree_leaf.generics.ContentT, haive.core.common.structures.tree_leaf.generics.ResultT]

Leaf node - has content but no children.

Examples

# With explicit types
leaf: Leaf[TaskContent, TaskResult] = Leaf(
    content=TaskContent(name="Calculate", action="add", params={"a": 1, "b": 2})
)

# With default types
simple_leaf = Leaf(content=DefaultContent(name="Task1"))
is_leaf()[source]¶

Is Leaf.

Returns:

Add return description]

Return type:

[TODO

class haive.core.common.structures.tree_leaf.base.Tree[source]¶

Bases: TreeNode[haive.core.common.structures.tree_leaf.generics.ContentT, haive.core.common.structures.tree_leaf.generics.ResultT], Generic[haive.core.common.structures.tree_leaf.generics.ContentT, haive.core.common.structures.tree_leaf.generics.ChildT, haive.core.common.structures.tree_leaf.generics.ResultT]

Tree node - has content and children.

The ChildT parameter allows for heterogeneous trees where children can be of different types (but all extending the bound).

Examples

# Homogeneous tree (all children same type)
tree: Tree[PlanContent, PlanNode, PlanResult] = Tree(
    content=PlanContent(objective="Main Plan")
)

# Heterogeneous tree (mixed children)
mixed: Tree[DefaultContent, TreeNode, DefaultResult] = Tree(
    content=DefaultContent(name="Root")
)
add_child(child: haive.core.common.structures.tree_leaf.generics.ChildT) haive.core.common.structures.tree_leaf.generics.ChildT[source]¶
add_child(*children: haive.core.common.structures.tree_leaf.generics.ChildT) list[haive.core.common.structures.tree_leaf.generics.ChildT]

Add one or more children with auto-indexing.

find_by_path(*indices)[source]¶

Find a descendant by path indices.

Parameters:

indices (int)

Return type:

haive.core.common.structures.tree_leaf.generics.ChildT | None

is_leaf()[source]¶

Is Leaf.

Returns:

Add return description]

Return type:

[TODO

property child_count: int¶

Number of direct children.

Return type:

int

property descendant_count: int¶

Total number of descendants.

Return type:

int

property height: int¶

Height of the subtree rooted at this node.

Return type:

int

class haive.core.common.structures.tree_leaf.base.TreeNode(/, **data)[source]¶

Bases: pydantic.BaseModel, Generic[haive.core.common.structures.tree_leaf.generics.ContentT, haive.core.common.structures.tree_leaf.generics.ResultT], abc.ABC

Abstract base class for all tree nodes.

Uses bounded TypeVars for better type safety and inference.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

abstractmethod is_leaf()[source]¶

Check if this is a leaf node.

Return type:

bool

property level: int¶

Tree level (alias for depth).

Return type:

int

property node_id: str¶

Unique identifier based on path.

Return type:

str