second pass at deterministic ordering

This version includes a much better description of how things work. Thanks to @stringertheory for helping to come up with an intuitive ordering that people would expect to see and a good suggestion for how to write TaskGraph.iter_tasks.