*digraph_tree
This commit is contained in:
parent
ea71d924f3
commit
9768c13793
16
srcxray.py
16
srcxray.py
|
@ -419,7 +419,7 @@ def digraph_tree(dg, starts=None):
|
||||||
def sub(node):
|
def sub(node):
|
||||||
tree.add_node(node)
|
tree.add_node(node)
|
||||||
for o in dg.successors(node):
|
for o in dg.successors(node):
|
||||||
if o in black_list or tree.has_edge(node, o):
|
if o in black_list or tree.has_node(o):
|
||||||
continue
|
continue
|
||||||
tree.add_edge(node,o)
|
tree.add_edge(node,o)
|
||||||
sub(o)
|
sub(o)
|
||||||
|
@ -430,12 +430,14 @@ def digraph_tree(dg, starts=None):
|
||||||
for i in [n for (n, d) in dg.in_degree if not d]:
|
for i in [n for (n, d) in dg.in_degree if not d]:
|
||||||
starts[i] = dg.out_degree(i)
|
starts[i] = dg.out_degree(i)
|
||||||
starts = [a[0] for a in sorted(starts.items(), key=lambda k: k[1], reverse=True)]
|
starts = [a[0] for a in sorted(starts.items(), key=lambda k: k[1], reverse=True)]
|
||||||
if len(starts) > 1:
|
if len(starts) == 1:
|
||||||
o.add_node('starts')
|
sub(starts[0])
|
||||||
for o in starts:
|
elif len(starts) > 1:
|
||||||
if o in black_list:
|
for o in starts:
|
||||||
continue
|
if o in black_list:
|
||||||
sub(o)
|
continue
|
||||||
|
tree.add_edge('start',o)
|
||||||
|
sub(o)
|
||||||
return tree
|
return tree
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue