the toposort code is fine, but the heap equality check isn't
It checks that both sets contain the same elements, but not that they are in the same order. I've added a new method EqualWithOrdering that tests that they are precisely equal and in the same order, and used it in the toposort code. I've not checked other callers of the Equal method to see if they should be changed as well.