Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def __linearize(self, linearizer:BaseLinearizer=None, unbinding=False):
- if not linearizer:
- linearizer = DEFAULT_LINEARIZER
- branching_points = set(self.iter_branching_points())
- childs = {message: sorted(childs) for message, childs in self.childs}
- leafs = sorted(set(self.iter_leafs()))
- branching_point = None
- node = leafs.pop()
- lines, tmp = [], []
- stack = []
- move_up = True
- while leafs:
- branching_node = node in branching_points
- n_childs = childs[node]
- if move_up and not branching_node:
- tmp = [node]+tmp
- node = node.ancestor
- elif move_up and branching_node:
- lines.append(tmp)
- branching_point = node.ancestor
- childs[branching_point].remove(tmp[0])
- node = childs[branching_point][-1]
- leafs.remove(tmp[-1])
- tmp = []
- move_up = False
- elif (not move_up) and not branching_node and n_childs:
- node = n_childs[0]
- tmp.append(node)
- elif (not move_up) and not branching_node and not n_childs:
- lines.append(tmp)
- childs[branching_point].remove(tmp[0])
- leafs.remove(node)
- tmp = []
- if childs[branching_point]:
- node = childs[branching_point][-1]
- else:
- lineified = linearizer.to_linear(*lines)
- lineified[0].ancestor = branching_point
- branching_points.remove(branching_point)
- for item, _next in zip(lineified[:-1], lineified[1:]):
- _next.ancestor = item
- if stack:
- node, lines, tmp, branching_point = stack.pop()
- else:
- node = lineified[-1]
- move_up = True
- elif (not move_up) and branching_node:
- stack.append((node, lines, tmp, branching_point))
- branching_point = node
- lines, tmp = [], []
Advertisement
Add Comment
Please, Sign In to add comment