Adding a generic topological sort for the update pipeline.

Not sure that I understand the semantics of this key comparison code. What does it mean to order to arbitrary keys?