Gliph\Traversal\DepthFirst::toposort PHP Method

toposort() public static method

Performs a topological sort on the provided graph.
public static toposort ( Gliph\Graph\Digraph $graph, object | SplDoublyLinkedList $start = NULL ) : array
$graph Gliph\Graph\Digraph
$start object | SplDoublyLinkedList The starting point(s) for the toposort. @see DepthFirst::traverse()
return array A valid topologically sorted list for the provided graph.
    public static function toposort(Digraph $graph, $start = NULL)
    {
        $visitor = new DepthFirstToposortVisitor();
        self::traverse($graph, $visitor, $start);
        return $visitor->getTsl();
    }

Usage Example

 /**
  * @covers \Gliph\Traversal\DepthFirst::toposort
  * @expectedException Gliph\Exception\RuntimeException
  *   Thrown by the visitor after adding a cycle to the graph.
  */
 public function testToposort()
 {
     extract($this->v);
     $this->assertEquals(array($c, $d, $b, $a), DepthFirst::toposort($this->g, $a));
     $this->g->addDirectedEdge($d, $a);
     DepthFirst::toposort($this->g, $a);
 }