Adding a generic topological sort for the update pipeline.

There's no intrinsic significance. Just one way to sort the keys in a deterministic manner.