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
Description
Currently the
TreeNodeclass 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 theTreeNodelist every time or preindexing.Having child references would simplify the traversal for this structure.
Questions/Ideas
TreeNodenodes with a tuplechildrencontaining the references to the child nodes.