Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1.  
  2.  
  3.  
  4. class NodeIndexHistory(object):
  5.     def __init__(self):
  6.         self._: List[int] = []
  7.  
  8.     def add(self, node: 'Node'):
  9.         if self.current():
  10.             Node.nodes_storage[node.index].back_str = self.current().back_str
  11.         self._.append(node.index)
  12.  
  13.     def set_root(self, root_node: 'Node'):
  14.         self._ = [root_node.index]
  15.  
  16.     def current(self) -> Union['Node', None]:
  17.         if len(self._):
  18.             return Node.nodes_storage[self._[-1]]
  19.         return None
  20.  
  21.     def can_back(self) -> bool:
  22.         return len(self._) > 1
  23.  
  24.     def back(self) -> 'Node':
  25.         self._.pop()
  26.         return self.current()
  27.  
  28.     def __len__(self):
  29.         return len(self._)
  30.  
  31.     def __repr__(self):
  32.         return '<{cls} nodes_number: {nn}>'.format(cls=self.__class__.__name__, nn=len(self))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement