Beispiel #1
0
 static function moveWithoutExtras($src, $dest)
 {
     if ($src->length !== $dest->length) {
         return null;
     }
     if ($src->length <= 1) {
         return new _hx_array(array());
     }
     $len = $src->length;
     $in_src = new haxe_ds_IntMap();
     $blk_len = new haxe_ds_IntMap();
     $blk_src_loc = new haxe_ds_IntMap();
     $blk_dest_loc = new haxe_ds_IntMap();
     $_g = 0;
     while ($_g < $len) {
         $i = $_g++;
         $in_src->set($src[$i], $i);
         $i;
         unset($i);
     }
     $ct = 0;
     $in_cursor = -2;
     $out_cursor = 0;
     $next = null;
     $blk = -1;
     $v = null;
     while ($out_cursor < $len) {
         $v = $dest[$out_cursor];
         $next = $in_src->get($v);
         if ($next !== $in_cursor + 1) {
             $blk = $v;
             $ct = 1;
             $blk_src_loc->set($blk, $next);
             $blk_dest_loc->set($blk, $out_cursor);
         } else {
             $ct++;
         }
         $blk_len->set($blk, $ct);
         $in_cursor = $next;
         $out_cursor++;
     }
     $blks = new _hx_array(array());
     if (null == $blk_len) {
         throw new HException('null iterable');
     }
     $__hx__it = $blk_len->keys();
     while ($__hx__it->hasNext()) {
         unset($k);
         $k = $__hx__it->next();
         $blks->push($k);
     }
     $blks->sort(array(new _hx_lambda(array(&$blk, &$blk_dest_loc, &$blk_len, &$blk_src_loc, &$blks, &$ct, &$dest, &$in_cursor, &$in_src, &$len, &$next, &$out_cursor, &$src, &$v), "coopy_Mover_0"), 'execute'));
     $moved = new _hx_array(array());
     while ($blks->length > 0) {
         $blk1 = $blks->shift();
         $blen = $blks->length;
         $ref_src_loc = $blk_src_loc->get($blk1);
         $ref_dest_loc = $blk_dest_loc->get($blk1);
         $i1 = $blen - 1;
         while ($i1 >= 0) {
             $blki = $blks[$i1];
             $blki_src_loc = $blk_src_loc->get($blki);
             $to_left_src = $blki_src_loc < $ref_src_loc;
             $to_left_dest = $blk_dest_loc->get($blki) < $ref_dest_loc;
             if ($to_left_src !== $to_left_dest) {
                 $ct1 = $blk_len->get($blki);
                 $_g1 = 0;
                 while ($_g1 < $ct1) {
                     $j = $_g1++;
                     $moved->push($src[$blki_src_loc]);
                     $blki_src_loc++;
                     unset($j);
                 }
                 unset($_g1);
                 $blks->splice($i1, 1);
                 unset($ct1);
             }
             $i1--;
             unset($to_left_src, $to_left_dest, $blki_src_loc, $blki);
         }
         unset($ref_src_loc, $ref_dest_loc, $i1, $blk1, $blen);
     }
     return $moved;
 }
 public function computeOrdering($mods, $permutation, $permutationRev, $dim)
 {
     $to_unit = new haxe_ds_IntMap();
     $from_unit = new haxe_ds_IntMap();
     $meta_from_unit = new haxe_ds_IntMap();
     $ct = 0;
     $_g = 0;
     while ($_g < $mods->length) {
         $mod = $mods[$_g];
         ++$_g;
         if ($mod->add || $mod->rem) {
             continue;
         }
         if ($mod->sourceRow < 0) {
             continue;
         }
         if ($mod->sourcePrevRow >= 0) {
             $v = $mod->sourceRow;
             $to_unit->set($mod->sourcePrevRow, $v);
             $v;
             unset($v);
             $v1 = $mod->sourcePrevRow;
             $from_unit->set($mod->sourceRow, $v1);
             $v1;
             unset($v1);
             if ($mod->sourcePrevRow + 1 !== $mod->sourceRow) {
                 $ct++;
             }
         }
         if ($mod->sourceNextRow >= 0) {
             $v2 = $mod->sourceNextRow;
             $to_unit->set($mod->sourceRow, $v2);
             $v2;
             unset($v2);
             $v3 = $mod->sourceRow;
             $from_unit->set($mod->sourceNextRow, $v3);
             $v3;
             unset($v3);
             if ($mod->sourceRow + 1 !== $mod->sourceNextRow) {
                 $ct++;
             }
         }
         unset($mod);
     }
     if ($ct > 0) {
         $cursor = null;
         $logical = null;
         $starts = new _hx_array(array());
         $_g1 = 0;
         while ($_g1 < $dim) {
             $i = $_g1++;
             $u = $from_unit->get($i);
             if ($u !== null) {
                 $meta_from_unit->set($u, $i);
                 $i;
             } else {
                 $starts->push($i);
             }
             unset($u, $i);
         }
         $used = new haxe_ds_IntMap();
         $len = 0;
         $_g2 = 0;
         while ($_g2 < $dim) {
             $i1 = $_g2++;
             if ($logical !== null && $meta_from_unit->exists($logical)) {
                 $cursor = $meta_from_unit->get($logical);
             } else {
                 $cursor = null;
             }
             if ($cursor === null) {
                 $v4 = $starts->shift();
                 $cursor = $v4;
                 $logical = $v4;
                 unset($v4);
             }
             if ($cursor === null) {
                 $cursor = 0;
             }
             while ($used->exists($cursor)) {
                 $cursor = _hx_mod($cursor + 1, $dim);
             }
             $logical = $cursor;
             $permutationRev->push($cursor);
             $used->set($cursor, 1);
             1;
             unset($i1);
         }
         $_g11 = 0;
         $_g3 = $permutationRev->length;
         while ($_g11 < $_g3) {
             $i2 = $_g11++;
             $permutation[$i2] = -1;
             unset($i2);
         }
         $_g12 = 0;
         $_g4 = $permutation->length;
         while ($_g12 < $_g4) {
             $i3 = $_g12++;
             $permutation[$permutationRev[$i3]] = $i3;
             unset($i3);
         }
     }
 }