46 if nodes and not stage: |
46 if nodes and not stage: |
47 # there is no element, which does not depend on some other element! |
47 # there is no element, which does not depend on some other element! |
48 stage.append(nodes[0]) |
48 stage.append(nodes[0]) |
49 |
49 |
50 taken.extend(stage) |
50 taken.extend(stage) |
51 nodes = list(filter(lambda x, l=stage: x not in l, nodes)) |
51 nodes = list(filter(lambda x, li=stage: x not in li, nodes)) |
52 while nodes: |
52 while nodes: |
53 previousStageChildren = [] |
53 previousStageChildren = [] |
54 nodelen = len(nodes) |
54 nodelen = len(nodes) |
55 |
55 |
56 # second stage are those nodes, which are direct children of the |
56 # second stage are those nodes, which are direct children of the |
78 while remove in stage: |
78 while remove in stage: |
79 stage.remove(remove) |
79 stage.remove(remove) |
80 |
80 |
81 stages.append(stage) |
81 stages.append(stage) |
82 taken.extend(stage) |
82 taken.extend(stage) |
83 nodes = list(filter(lambda x, l=stage: x not in l, nodes)) |
83 nodes = list(filter(lambda x, li=stage: x not in li, nodes)) |
84 if nodelen == len(nodes): |
84 if nodelen == len(nodes): |
85 if noRecursion: |
85 if noRecursion: |
86 raise RecursionError(nodes) |
86 raise RecursionError(nodes) |
87 else: |
87 else: |
88 stages.append(nodes[:]) |
88 stages.append(nodes[:]) |