High-Performance Topological Sort / Dependency resolver in PHP