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 node - contains content and children. |
|
Leaf node - contains content but no children. |
|
Status for tree nodes. |
|
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:
child (Union[Leaf[ContentType, ResultType], Branch[ContentType, ResultType]])
auto_index (bool)
- 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:
- 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]]
- 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 next_pending_leaf: Leaf[ContentType, ResultType] | NoneΒΆ
Get the next pending leaf node (depth-first).
- Return type:
Leaf[ContentType, ResultType] | None
- class haive.core.common.structures.generic_tree.Leaf[source]ΒΆ
Bases:
TreeNode
[ContentType
,ResultType
]Leaf node - contains content but no children.
- class haive.core.common.structures.generic_tree.NodeStatus[source]ΒΆ
-
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)
- 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:
result (ResultType)
status (NodeStatus)
- Return type:
None