@@ -454,24 +454,19 @@ def remove_transitive_edges(graph):
454454 ret [parent ] = lst
455455 return ret
456456
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 )
468463
469464 def transitive_closure (graph ):
470465 ret = {}
471466 for parent , children in graph .items ():
472467 lst = []
473468 for child in children :
474- get_all_ancestors (set (), lst , graph , child )
469+ get_transitive_children (set (), lst , graph , child )
475470 ret [parent ] = lst
476471 return ret
477472
0 commit comments