Esempio n. 1
0
 def is_node_on_tree(self, node: Node) -> bool:
     is_on_tree = self._root.__eq__(node.get_root())
     is_on_tree = is_on_tree and (self._root.__eq__(node.get_root()))
     is_on_tree = is_on_tree and (node.count_node_level()
                                  in self._node_on_tree)
     is_on_tree = is_on_tree and (
         node.get_name_full()
         in self._node_on_tree[node.count_node_level()].keys())
     return is_on_tree
Esempio n. 2
0
 def add_node_to_tree(self, node: Node):
     if not self._root.__eq__(node.get_root()):
         raise ValueError('cannot add node from other tree')
     node_level = node.count_node_level()
     while not self.is_node_on_tree(node):
         parent_node = node.get_parent()
         if self.is_node_on_tree(parent_node):
             # add target node to the tree
             if node_level not in self._node_on_tree:
                 self._node_on_tree[node_level] = {}
             self._node_on_tree[node_level][node.get_name_full()] = node
             # update target parent node on tree
             parent_node_level = parent_node.count_node_level()
             self._node_on_tree[parent_node_level][
                 parent_node.get_name_full()].add_child(node)
         else:
             self.add_node_to_tree(node.get_parent())
     pass