Guest User

pzdc.py

a guest
Aug 25th, 2020
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.20 KB | None | 0 0
  1.     def __linearize(self, linearizer:BaseLinearizer=None, unbinding=False):
  2.         if not linearizer:
  3.             linearizer = DEFAULT_LINEARIZER
  4.         branching_points = set(self.iter_branching_points())
  5.         childs = {message: sorted(childs) for message, childs in self.childs}
  6.         leafs = sorted(set(self.iter_leafs()))
  7.         branching_point = None
  8.         node = leafs.pop()
  9.         lines, tmp = [], []
  10.         stack = []
  11.         move_up = True
  12.         while leafs:
  13.             branching_node = node in branching_points
  14.             n_childs = childs[node]
  15.             if move_up and not branching_node:
  16.                 tmp = [node]+tmp
  17.                 node = node.ancestor
  18.             elif move_up and branching_node:
  19.                 lines.append(tmp)
  20.                 branching_point = node.ancestor
  21.                 childs[branching_point].remove(tmp[0])
  22.                 node = childs[branching_point][-1]
  23.                 leafs.remove(tmp[-1])
  24.                 tmp = []
  25.                 move_up = False
  26.             elif (not move_up) and not branching_node and n_childs:
  27.                 node = n_childs[0]
  28.                 tmp.append(node)
  29.             elif (not move_up) and not branching_node and not n_childs:
  30.                 lines.append(tmp)
  31.                 childs[branching_point].remove(tmp[0])
  32.                 leafs.remove(node)
  33.                 tmp = []
  34.                 if childs[branching_point]:
  35.                     node = childs[branching_point][-1]
  36.                 else:
  37.                     lineified = linearizer.to_linear(*lines)
  38.                     lineified[0].ancestor = branching_point
  39.                     branching_points.remove(branching_point)
  40.                     for item, _next in zip(lineified[:-1], lineified[1:]):
  41.                         _next.ancestor = item
  42.                     if stack:
  43.                         node, lines, tmp, branching_point = stack.pop()
  44.                     else:
  45.                         node = lineified[-1]
  46.                         move_up = True
  47.             elif (not move_up) and branching_node:
  48.                 stack.append((node, lines, tmp, branching_point))
  49.                 branching_point = node
  50.                 lines, tmp = [], []
Advertisement
Add Comment
Please, Sign In to add comment