Skip to content

Add child references to TreeNode #469

@folmos-at-orange

Description

@folmos-at-orange

Description

Currently the TreeNode class contains only a reference to a parent. This is very unusual for a tree structure, and while still it is possible to traverse it requires consulting the TreeNode list every time or preindexing.

Having child references would simplify the traversal for this structure.

Questions/Ideas

  • After reading the object, index the TreeNode nodes with a tuple children containing the references to the child nodes.
  • Indexation example
# This uses the fact that the node list is in BFS
nodes_index = {}
for node in tree.nodes:
    nodes_index[node.id] = node
    node.left_child = None
    node.right_child = None
    if node.parent_id is not None:
        parent_node = nodes_index[node.parent_id]
        if parent_node.left_child is None:
            parent_node.left_child = node
        else:
            parent_node.right_child = node

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority/2-LowTo do after P1Size/DaysSome days of workStatus/ReadyForDevThe issue is ready to be developed or to be investigated deeply

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions