Topological sort with the tsort modified hash class