Given an unsorted set of structures which can each contain other structures (in that set, or new structures), how can I compute a resolution order such that never process structure A before another structure that contains A?