From e2f1e3aefba00e3f520af5448f9b406544358a22 Mon Sep 17 00:00:00 2001 From: Costa Shulyupin Date: Tue, 7 Aug 2018 09:07:08 +0300 Subject: [PATCH] +remove_loops --- srcxray.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/srcxray.py b/srcxray.py index 39784db..8675259 100755 --- a/srcxray.py +++ b/srcxray.py @@ -697,6 +697,30 @@ def to_dg(a): return read_dot2(a) +def remove_loops(dg): + rm = [] + visited = set() + path = [object()] + path_set = set(path) + stack = [iter(dg)] + while stack: + for v in stack[-1]: + if v in path_set: + rm.append((path[-1], v)) + elif v not in visited: + visited.add(v) + path.append(v) + path_set.add(v) + stack.append(iter(dg[v])) + break + else: + path_set.remove(path.pop()) + stack.pop() + # print(rm) + dg.remove_edges_from(rm) + return dg + + def cflow_linux(): dirs = ('init kernel kernel/time ' 'fs fs/ext4 block '