@@ -454,24 +454,19 @@ def remove_transitive_edges(graph):
454
454
ret [parent ] = lst
455
455
return ret
456
456
457
- def get_all_ancestors (recur , lst , graph , ancestor_name ):
458
- if ancestor_name not in recur :
459
- recur = recur .copy ()
460
- recur .add (ancestor_name )
461
-
462
- if ancestor_name not in lst :
463
- lst .append (ancestor_name )
464
-
465
- existing_ancestors = graph .get (ancestor_name , [])
466
- for existing in existing_ancestors :
467
- get_all_ancestors (recur , lst , graph , existing )
457
+ def get_transitive_children (recur , lst , graph , current ):
458
+ if current not in recur :
459
+ recur .add (current )
460
+ lst .append (current )
461
+ for child in graph .get (current , []):
462
+ get_transitive_children (recur , lst , graph , child )
468
463
469
464
def transitive_closure (graph ):
470
465
ret = {}
471
466
for parent , children in graph .items ():
472
467
lst = []
473
468
for child in children :
474
- get_all_ancestors (set (), lst , graph , child )
469
+ get_transitive_children (set (), lst , graph , child )
475
470
ret [parent ] = lst
476
471
return ret
477
472
0 commit comments