haive.core.common.structures.generic_treeΒΆ

Generic Tree/Leaf model with auto-indexing and type safety.

This module provides a powerful generic tree structure that can be used for any hierarchical data, with automatic indexing, computed properties, and full type safety through generics.

ClassesΒΆ

Branch

Branch node - contains content and children.

Leaf

Leaf node - contains content but no children.

NodeStatus

Status for tree nodes.

TreeNode

Abstract base class for tree nodes.

Module ContentsΒΆ

class haive.core.common.structures.generic_tree.Branch[source]ΒΆ

Bases: TreeNode[ContentType, ResultType], Generic[ContentType, ResultType]

Branch node - contains content and children.

add_branch(content)[source]ΒΆ

Convenience method to add a branch child.

Parameters:

content (ContentType)

Return type:

Branch[ContentType, ResultType]

add_child(child, auto_index=True)[source]ΒΆ

Add a child node with auto-indexing.

Parameters:
Return type:

Union[Leaf[ContentType, ResultType], Branch[ContentType, ResultType]]

add_leaf(content)[source]ΒΆ

Convenience method to add a leaf child.

Parameters:

content (ContentType)

Return type:

Leaf[ContentType, ResultType]

add_parallel_children(children)[source]ΒΆ

Add multiple children that represent parallel execution.

Parameters:

children (list[Union[Leaf[ContentType, ResultType], Branch[ContentType, ResultType]]])

Return type:

list[Union[Leaf[ContentType, ResultType], Branch[ContentType, ResultType]]]

find_node_by_path(path)[source]ΒΆ

Find a node by its path indices.

Parameters:

path (list[int])

Return type:

Union[Leaf[ContentType, ResultType], Branch[ContentType, ResultType]] | None

get_all_leaves()[source]ΒΆ

Get all leaf nodes in this subtree.

Return type:

list[Leaf[ContentType, ResultType]]

is_leaf()[source]ΒΆ

Is Leaf.

Returns:

Add return description]

Return type:

[TODO

property completed_count: intΒΆ

Number of completed nodes.

Return type:

int

property current_active_nodes: list[Leaf[ContentType, ResultType] | Branch[ContentType, ResultType]]ΒΆ

Get all nodes currently in progress.

Return type:

list[Union[Leaf[ContentType, ResultType], Branch[ContentType, ResultType]]]

property failed_count: intΒΆ

Number of failed nodes.

Return type:

int

property has_failures: boolΒΆ

Whether any node in this subtree has failed.

Return type:

bool

property is_complete: boolΒΆ

Whether all nodes in this subtree are complete.

Return type:

bool

property leaf_count: intΒΆ

Number of leaf nodes in this subtree.

Return type:

int

property next_pending_leaf: Leaf[ContentType, ResultType] | NoneΒΆ

Get the next pending leaf node (depth-first).

Return type:

Leaf[ContentType, ResultType] | None

property progress_percentage: floatΒΆ

Percentage of completion (0-100).

Return type:

float

property total_nodes: intΒΆ

Total number of nodes in this subtree.

Return type:

int

class haive.core.common.structures.generic_tree.Leaf[source]ΒΆ

Bases: TreeNode[ContentType, ResultType]

Leaf node - contains content but no children.

is_leaf()[source]ΒΆ

Is Leaf.

Returns:

Add return description]

Return type:

[TODO

property is_complete: boolΒΆ

Whether this leaf is complete.

Return type:

bool

class haive.core.common.structures.generic_tree.NodeStatus[source]ΒΆ

Bases: str, enum.Enum

Status for tree nodes.

Initialize self. See help(type(self)) for accurate signature.

class haive.core.common.structures.generic_tree.TreeNode(/, **data)[source]ΒΆ

Bases: pydantic.BaseModel, Generic[ContentType, ResultType], abc.ABC

Abstract base class for tree nodes.

Provides common functionality for both leaf and branch nodes.

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]ΒΆ

Whether this is a leaf node.

Return type:

bool

mark_failed(error)[source]ΒΆ

Mark node as failed with error message.

Parameters:

error (str)

Return type:

None

set_result(result, status=NodeStatus.COMPLETED)[source]ΒΆ

Set the result and update status.

Parameters:
Return type:

None