Open the context
Choose the project folder and name the files or behavior involved.
Group up to 64 dependency nodes into sorted topological generations from sets of prerequisite indices. Test independent nodes and empty input, reject cycles, self-dependencies and invalid indices, and retain the original sets.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
def dependency_layers(dependencies):
if type(dependencies) is not list or len(dependencies) > 64:
raise ValueError("layers.input")
count = len(dependencies)
if any(type(row) is not set or any(type(v) is not int or not 0 <= v < count for v in row) for row in dependencies):
raise ValueError("layers.edge")
pending, done, layers = set(range(count)), set(), []
while pending:
ready = sorted(i for i in pending if dependencies[i] <= done)
if not ready:
raise ValueError("layers.cycle")
layers.append(ready)
pending.difference_update(ready)
done.update(ready)
return layers
The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.