Actually, the Comparator approach won't work directly since this is really just a partial ordering. A topological sort?