function Graph::__construct

Same name in other branches
  1. 8.9.x core/lib/Drupal/Component/Graph/Graph.php \Drupal\Component\Graph\Graph::__construct()
  2. 10 core/lib/Drupal/Component/Graph/Graph.php \Drupal\Component\Graph\Graph::__construct()
  3. 11.x core/lib/Drupal/Component/Graph/Graph.php \Drupal\Component\Graph\Graph::__construct()

Instantiates the depth first search object.

Parameters

$graph: A three dimensional associated array, with the first keys being the names of the vertices, these can be strings or numbers. The second key is 'edges' and the third one are again vertices, each such key representing an edge. Values of array elements are copied over.

Example:

$graph[1]['edges'][2] = 1;
$graph[2]['edges'][3] = 1;
$graph[2]['edges'][4] = 1;
$graph[3]['edges'][4] = 1;

On return you will also have:

$graph[1]['paths'][2] = 1;
$graph[1]['paths'][3] = 1;
$graph[2]['reverse_paths'][1] = 1;
$graph[3]['reverse_paths'][1] = 1;

File

core/lib/Drupal/Component/Graph/Graph.php, line 40

Class

Graph
Directed acyclic graph manipulation.

Namespace

Drupal\Component\Graph

Code

public function __construct($graph) {
    $this->graph = $graph;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.