Exemple #1
0
 /**
  * @covers ::array_unique
  * @covers ::getKey
  */
 public function testArrayUnique()
 {
     $from = [1, 2, $a = new \StdClass(), $b = new \StdClass(), $a, 1, 2];
     $to = [1, 2, $a, $b];
     $this->assertSame($to, Shim::array_unique($from));
 }
Exemple #2
0
 public static function findAllSuccessors(Vertex $node, Digraph $graph)
 {
     if (is_null(self::$processing)) {
         self::$processing = new \SplObjectStorage();
     }
     if (self::$processing->contains($node)) {
         return array();
     }
     self::$processing[$node] = true;
     $result = array();
     foreach ($graph->successorsOf($node) as $sub) {
         $result[] = $sub;
         $result = array_merge($result, self::findAllSuccessors($sub, $graph));
     }
     self::$processing->detach($node);
     return Shim::array_unique($result);
 }
Exemple #3
0
 /**
  * Reduce the generated tree to only contain the actual dominators
  *
  * This is an inefficient algorithm. It is approximately O(n^2).
  */
 protected function reduce(Vertex $start)
 {
     $changed = true;
     while ($changed) {
         $changed = false;
         foreach ($this->graph->vertices() as $vertex) {
             if ($vertex === $start) {
                 continue;
             }
             $pred = $this->iPredecessors[$vertex];
             if (empty($pred)) {
                 continue;
             }
             $new = $this->dominator[$pred[0]];
             for ($i = 1; $i < count($pred); $i++) {
                 $new = Shim::array_intersect($new, $this->dominator[$pred[$i]]);
             }
             $new = array_merge($new, [$vertex]);
             if ($new !== $this->dominator[$vertex]) {
                 $changed = true;
                 $this->dominator[$vertex] = $new;
             }
         }
     }
 }