traverse() public static method

Perform a depth-first traversal on the provided graph.
public static traverse ( Gliph\Graph\Digraph $graph, Gliph\Visitor\DepthFirstVisitorInterface $visitor, object | SplDoublyLinkedList $start = NULL )
$graph Gliph\Graph\Digraph The graph on which to perform the depth-first search.
$visitor Gliph\Visitor\DepthFirstVisitorInterface The visitor object to use during the traversal.
$start object | SplDoublyLinkedList A vertex, or vertices, to use as start points for the traversal. There are a few sub-behaviors here: - If an SplDoublyLinkedList, SplQueue, or SplStack is provided, the traversal will deque and visit vertices contained therein. - If a single vertex object is provided, it will be the sole originating point for the traversal. - If no value is provided, DepthFirst::find_sources() is called to search the graph for source vertices. These are place into an SplQueue in the order in which they are discovered, and traversal is then run over that queue in the same manner as if calling code had provided a queue directly. This method *guarantees* that all vertices in the graph will be visited.
 /**
  * {@inheritdoc}
  */
 public function isAcyclic()
 {
     // The DepthFirstToposortVisitor throws an exception on cycles.
     try {
         DepthFirst::traverse($this, new DepthFirstToposortVisitor());
         return TRUE;
     } catch (RuntimeException $e) {
         return FALSE;
     }
 }
示例#2
0
 /**
  * @covers Gliph\Traversal\DepthFirst::traverse
  */
 public function testProvideQueueAsStartPoint()
 {
     extract($this->v);
     $queue = new \SplQueue();
     $queue->push($a);
     $queue->push($e);
     $this->g->addVertex($a);
     $this->g->addVertex($e);
     DepthFirst::traverse($this->g, new DepthFirstNoOpVisitor(), $queue);
 }
 public function testReachableExceptionOnUnknownVertex()
 {
     DepthFirst::traverse($this->g, $this->vis, $this->v['a']);
     $this->assertFalse($this->vis->getReachable($this->v['e']));
 }