示例#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));
 }
示例#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);
 }
示例#3
0
 /**
  * Find the immediate dominator of a set of vertices
  *
  * The idom is the unique dominator of the vertex which dominates
  * no other dominator of the vertex.
  *
  * @param Vertex[] $vertices The vertex
  *
  * @return mixed The vertex or null if no idom exists
  */
 public function immediateDominatorArray(array $vertices)
 {
     $idoms = [];
     foreach ($vertices as $vertex) {
         $idoms[] = $this->immediateDominator($vertex);
     }
     while (!empty($idoms)) {
         $idoms = array_filter(Shim::array_unique($idoms));
         $toremove = [];
         foreach ($idoms as $k => $v1) {
             foreach ($idoms as $v2) {
                 if ($this->strictlyDominates($v1, $v2)) {
                     $toremove[] = $k;
                 }
             }
         }
         foreach ($toremove as $k) {
             unset($idoms[$k]);
         }
         if (count($idoms) === 1) {
             return reset($idoms);
         }
         $newidoms = [];
         foreach ($idoms as $idom) {
             $newidoms[] = $this->immediateDominator($idom);
         }
         $idoms = $newidoms;
     }
 }