For something like task scheduling in a build system, if you use an up-front partition of the tasks like this, you may have a task that has all its dependencies fulfilled because tasks may have different durations, but still remains unscheduled. For example, with this input: $ cat data.file root: parentA parentB parentA: C D parentB: E F Asking the package tool for the sorted sets gives me: $ ./zig-out/bin/toposort-c…
{C D E F}, {parentA parentB}, {root}
Within a batch, nodes can run parallel. Between batches, they still need to run one after another.What you're asking for is to partition the dependency graph according to node dependency with minimum span.
{ {C D} parentA } \
{ {E F} parentB } - {root}
Or with a shared leader. { {C D S} parentA } \
{ {E F S} parentB } - {root}
And on top of that, add node weight into the consideration. That's hard.For now, you can send notification to a dependent when the leading task finishes. E.g. When C finishes, notifies parentA. When D finishes, notifies parentA. When parentA notices that all its leading tasks have done, it can start.
The library can help in maintaining the dependency relationship and let the task query its leaders and dependents.
For task running, it would be a separate library using the TopoSort library and specifically geared toward scheduling tasks.