Пример #1
0
 public function trimBlank()
 {
     if ($this->h === 0) {
         return true;
     }
     $h_test = $this->h;
     if ($h_test >= 3) {
         $h_test = 3;
     }
     $view = $this->getCellView();
     $space = $view->toDatum("");
     $more = true;
     while ($more) {
         $_g1 = 0;
         $_g = $this->get_width();
         while ($_g1 < $_g) {
             $i = $_g1++;
             $c = $this->getCell($i, $this->h - 1);
             if (!($view->equals($c, $space) || $c === null)) {
                 $more = false;
                 break;
             }
             unset($i, $c);
         }
         unset($_g1, $_g);
         if ($more) {
             $this->h--;
         }
     }
     $more = true;
     $nw = $this->w;
     while ($more) {
         if ($this->w === 0) {
             break;
         }
         $_g2 = 0;
         while ($_g2 < $h_test) {
             $i1 = $_g2++;
             $c1 = $this->getCell($nw - 1, $i1);
             if (!($view->equals($c1, $space) || $c1 === null)) {
                 $more = false;
                 break;
             }
             unset($i1, $c1);
         }
         unset($_g2);
         if ($more) {
             $nw--;
         }
     }
     if ($nw === $this->w) {
         return true;
     }
     $data2 = new haxe_ds_IntMap();
     $_g3 = 0;
     while ($_g3 < $nw) {
         $i2 = $_g3++;
         $_g21 = 0;
         $_g11 = $this->h;
         while ($_g21 < $_g11) {
             $r = $_g21++;
             $idx = $r * $this->w + $i2;
             if ($this->data->exists($idx)) {
                 $value = $this->data->get($idx);
                 $data2->set($r * $nw + $i2, $value);
                 unset($value);
             }
             unset($r, $idx);
         }
         unset($_g21, $_g11);
         unset($i2);
     }
     $this->w = $nw;
     $this->data = $data2;
     return true;
 }
Пример #2
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 alignCore2($align, $a, $b)
 {
     if ($align->meta === null) {
         $align->meta = new coopy_Alignment();
     }
     $this->alignColumns($align->meta, $a, $b);
     $column_order = $align->meta->toOrder();
     $align->range($a->get_height(), $b->get_height());
     $align->tables($a, $b);
     $align->setRowlike(true);
     $w = $a->get_width();
     $ha = $a->get_height();
     $hb = $b->get_height();
     $av = $a->getCellView();
     $ids = null;
     $ignore = null;
     if ($this->comp->compare_flags !== null) {
         $ids = $this->comp->compare_flags->ids;
         $ignore = $this->comp->compare_flags->getIgnoredColumns();
     }
     $common_units = new _hx_array(array());
     $ra_header = $align->getSourceHeader();
     $rb_header = $align->getSourceHeader();
     $_g = 0;
     $_g1 = $column_order->getList();
     while ($_g < $_g1->length) {
         $unit = $_g1[$_g];
         ++$_g;
         if ($unit->l >= 0 && $unit->r >= 0 && $unit->p !== -1) {
             if ($ignore !== null) {
                 if ($unit->l >= 0 && $ra_header >= 0 && $ra_header < $a->get_height()) {
                     $name = $av->toString($a->getCell($unit->l, $ra_header));
                     if ($ignore->exists($name)) {
                         continue;
                     }
                     unset($name);
                 }
                 if ($unit->r >= 0 && $rb_header >= 0 && $rb_header < $b->get_height()) {
                     $name1 = $av->toString($b->getCell($unit->r, $rb_header));
                     if ($ignore->exists($name1)) {
                         continue;
                     }
                     unset($name1);
                 }
             }
             $common_units->push($unit);
         }
         unset($unit);
     }
     $index_top = null;
     $pending_ct = $ha;
     $reverse_pending_ct = $hb;
     $used = new haxe_ds_IntMap();
     $used_reverse = new haxe_ds_IntMap();
     if ($ids !== null) {
         $index_top = new coopy_IndexPair($this->comp->compare_flags);
         $ids_as_map = new haxe_ds_StringMap();
         $_g2 = 0;
         while ($_g2 < $ids->length) {
             $id = $ids[$_g2];
             ++$_g2;
             $ids_as_map->set($id, true);
             true;
             unset($id);
         }
         $_g3 = 0;
         while ($_g3 < $common_units->length) {
             $unit1 = $common_units[$_g3];
             ++$_g3;
             $na = $av->toString($a->getCell($unit1->l, 0));
             $nb = $av->toString($b->getCell($unit1->r, 0));
             if ($ids_as_map->exists($na) || $ids_as_map->exists($nb)) {
                 $index_top->addColumns($unit1->l, $unit1->r);
                 $align->addIndexColumns($unit1);
             }
             unset($unit1, $nb, $na);
         }
         $index_top->indexTables($a, $b, 1);
         if ($this->indexes !== null) {
             $this->indexes->push($index_top);
         }
         $_g4 = 0;
         while ($_g4 < $ha) {
             $j = $_g4++;
             $cross = $index_top->queryLocal($j);
             $spot_a = $cross->spot_a;
             $spot_b = $cross->spot_b;
             if ($spot_a !== 1 || $spot_b !== 1) {
                 continue;
             }
             $jb = $cross->item_b->lst[0];
             $align->link($j, $jb);
             $used->set($jb, 1);
             if (!$used_reverse->exists($j)) {
                 $reverse_pending_ct--;
             }
             $used_reverse->set($j, 1);
             unset($spot_b, $spot_a, $jb, $j, $cross);
         }
     } else {
         $N = 5;
         $columns = new _hx_array(array());
         if ($common_units->length > $N) {
             $columns_eval = new _hx_array(array());
             $_g11 = 0;
             $_g5 = $common_units->length;
             while ($_g11 < $_g5) {
                 $i = $_g11++;
                 $ct = 0;
                 $mem = new haxe_ds_StringMap();
                 $mem2 = new haxe_ds_StringMap();
                 $ca = _hx_array_get($common_units, $i)->l;
                 $cb = _hx_array_get($common_units, $i)->r;
                 $_g21 = 0;
                 while ($_g21 < $ha) {
                     $j1 = $_g21++;
                     $key = $av->toString($a->getCell($ca, $j1));
                     if (!$mem->exists($key)) {
                         $mem->set($key, 1);
                         $ct++;
                     }
                     unset($key, $j1);
                 }
                 unset($_g21);
                 $_g22 = 0;
                 while ($_g22 < $hb) {
                     $j2 = $_g22++;
                     $key1 = $av->toString($b->getCell($cb, $j2));
                     if (!$mem2->exists($key1)) {
                         $mem2->set($key1, 1);
                         $ct++;
                     }
                     unset($key1, $j2);
                 }
                 unset($_g22);
                 $columns_eval->push(new _hx_array(array($i, $ct)));
                 unset($mem2, $mem, $i, $ct, $cb, $ca);
             }
             $sorter = array(new _hx_lambda(array(&$N, &$a, &$align, &$av, &$b, &$column_order, &$columns, &$columns_eval, &$common_units, &$ha, &$hb, &$ids, &$ignore, &$index_top, &$pending_ct, &$ra_header, &$rb_header, &$reverse_pending_ct, &$used, &$used_reverse, &$w), "coopy_CompareTable_0"), 'execute');
             $columns_eval->sort($sorter);
             $columns = Lambda::harray(Lambda::map($columns_eval, array(new _hx_lambda(array(&$N, &$a, &$align, &$av, &$b, &$column_order, &$columns, &$columns_eval, &$common_units, &$ha, &$hb, &$ids, &$ignore, &$index_top, &$pending_ct, &$ra_header, &$rb_header, &$reverse_pending_ct, &$sorter, &$used, &$used_reverse, &$w), "coopy_CompareTable_1"), 'execute')));
             $columns = $columns->slice(0, $N);
         } else {
             $_g12 = 0;
             $_g6 = $common_units->length;
             while ($_g12 < $_g6) {
                 $i1 = $_g12++;
                 $columns->push($i1);
                 unset($i1);
             }
         }
         $top = Math::round(Math::pow(2, $columns->length));
         $pending = new haxe_ds_IntMap();
         $_g7 = 0;
         while ($_g7 < $ha) {
             $j3 = $_g7++;
             $pending->set($j3, $j3);
             unset($j3);
         }
         $added_columns = new haxe_ds_IntMap();
         $index_ct = 0;
         $_g8 = 0;
         while ($_g8 < $top) {
             $k = $_g8++;
             if ($k === 0) {
                 continue;
             }
             if ($pending_ct === 0) {
                 break;
             }
             $active_columns = new _hx_array(array());
             $kk = $k;
             $at = 0;
             while ($kk > 0) {
                 if (_hx_mod($kk, 2) === 1) {
                     $active_columns->push($columns[$at]);
                 }
                 $kk >>= 1;
                 $at++;
             }
             $index = new coopy_IndexPair($this->comp->compare_flags);
             $_g23 = 0;
             $_g13 = $active_columns->length;
             while ($_g23 < $_g13) {
                 $k1 = $_g23++;
                 $col = $active_columns[$k1];
                 $unit2 = $common_units[$col];
                 $index->addColumns($unit2->l, $unit2->r);
                 if (!$added_columns->exists($col)) {
                     $align->addIndexColumns($unit2);
                     $added_columns->set($col, true);
                 }
                 unset($unit2, $k1, $col);
             }
             unset($_g23, $_g13);
             $index->indexTables($a, $b, 1);
             if ($k === $top - 1) {
                 $index_top = $index;
             }
             $h = $a->get_height();
             if ($b->get_height() > $h) {
                 $h = $b->get_height();
             }
             if ($h < 1) {
                 $h = 1;
             }
             $wide_top_freq = $index->getTopFreq();
             $ratio = $wide_top_freq;
             $ratio /= $h + 20;
             if ($ratio >= 0.1) {
                 if ($index_ct > 0 || $k < $top - 1) {
                     continue;
                 }
             }
             $index_ct++;
             if ($this->indexes !== null) {
                 $this->indexes->push($index);
             }
             $fixed = new _hx_array(array());
             if (null == $pending) {
                 throw new HException('null iterable');
             }
             $__hx__it = $pending->keys();
             while ($__hx__it->hasNext()) {
                 unset($j4);
                 $j4 = $__hx__it->next();
                 $cross1 = $index->queryLocal($j4);
                 $spot_a1 = $cross1->spot_a;
                 $spot_b1 = $cross1->spot_b;
                 if ($spot_a1 !== 1 || $spot_b1 !== 1) {
                     continue;
                 }
                 $val = $cross1->item_b->lst[0];
                 if (!$used->exists($val)) {
                     $fixed->push($j4);
                     $align->link($j4, $val);
                     $used->set($val, 1);
                     if (!$used_reverse->exists($j4)) {
                         $reverse_pending_ct--;
                     }
                     $used_reverse->set($j4, 1);
                 }
                 unset($val, $spot_b1, $spot_a1, $cross1);
             }
             $_g24 = 0;
             $_g14 = $fixed->length;
             while ($_g24 < $_g14) {
                 $j5 = $_g24++;
                 $pending->remove($fixed[$j5]);
                 $pending_ct--;
                 unset($j5);
             }
             unset($_g24, $_g14);
             unset($wide_top_freq, $ratio, $kk, $k, $index, $h, $fixed, $at, $active_columns);
         }
     }
     if ($index_top !== null) {
         $offset = 0;
         $scale = 1;
         $_g9 = 0;
         while ($_g9 < 2) {
             $sgn = $_g9++;
             if ($pending_ct > 0) {
                 $xb = null;
                 if ($scale === -1 && $hb > 0) {
                     $xb = $hb - 1;
                 }
                 $_g15 = 0;
                 while ($_g15 < $ha) {
                     $xa0 = $_g15++;
                     $xa = $xa0 * $scale + $offset;
                     $xb2 = $align->a2b($xa);
                     if ($xb2 !== null) {
                         $xb = $xb2 + $scale;
                         if ($xb >= $hb || $xb < 0) {
                             break;
                         }
                         continue;
                     }
                     if ($xb === null) {
                         continue;
                     }
                     $ka = $index_top->localKey($xa);
                     $kb = $index_top->remoteKey($xb);
                     if ($ka !== $kb) {
                         continue;
                     }
                     if ($used->exists($xb)) {
                         continue;
                     }
                     $align->link($xa, $xb);
                     $used->set($xb, 1);
                     $used_reverse->set($xa, 1);
                     $pending_ct--;
                     $xb += $scale;
                     if ($xb >= $hb || $xb < 0) {
                         break;
                     }
                     if ($pending_ct === 0) {
                         break;
                     }
                     unset($xb2, $xa0, $xa, $kb, $ka);
                 }
                 unset($_g15);
                 unset($xb);
             }
             $offset = $ha - 1;
             $scale = -1;
             unset($sgn);
         }
         $offset = 0;
         $scale = 1;
         $_g10 = 0;
         while ($_g10 < 2) {
             $sgn1 = $_g10++;
             if ($reverse_pending_ct > 0) {
                 $xa1 = null;
                 if ($scale === -1 && $ha > 0) {
                     $xa1 = $ha - 1;
                 }
                 $_g16 = 0;
                 while ($_g16 < $hb) {
                     $xb0 = $_g16++;
                     $xb1 = $xb0 * $scale + $offset;
                     $xa2 = $align->b2a($xb1);
                     if ($xa2 !== null) {
                         $xa1 = $xa2 + $scale;
                         if ($xa1 >= $ha || $xa1 < 0) {
                             break;
                         }
                         continue;
                     }
                     if ($xa1 === null) {
                         continue;
                     }
                     $ka1 = $index_top->localKey($xa1);
                     $kb1 = $index_top->remoteKey($xb1);
                     if ($ka1 !== $kb1) {
                         continue;
                     }
                     if ($used_reverse->exists($xa1)) {
                         continue;
                     }
                     $align->link($xa1, $xb1);
                     $used->set($xb1, 1);
                     $used_reverse->set($xa1, 1);
                     $reverse_pending_ct--;
                     $xa1 += $scale;
                     if ($xa1 >= $ha || $xa1 < 0) {
                         break;
                     }
                     if ($reverse_pending_ct === 0) {
                         break;
                     }
                     unset($xb1, $xb0, $xa2, $kb1, $ka1);
                 }
                 unset($_g16);
                 unset($xa1);
             }
             $offset = $hb - 1;
             $scale = -1;
             unset($sgn1);
         }
     }
     $_g17 = 1;
     while ($_g17 < $ha) {
         $i2 = $_g17++;
         if (!$used_reverse->exists($i2)) {
             $align->link($i2, -1);
         }
         unset($i2);
     }
     $_g18 = 1;
     while ($_g18 < $hb) {
         $i3 = $_g18++;
         if (!$used->exists($i3)) {
             $align->link(-1, $i3);
         }
         unset($i3);
     }
     if ($ha > 0 && $hb > 0) {
         $align->link(0, 0);
     }
 }
Пример #4
0
 public function finishColumns()
 {
     if ($this->finished_columns) {
         return;
     }
     $this->finished_columns = true;
     $this->needSourceColumns();
     $_g1 = $this->payloadCol;
     $_g = $this->payloadTop;
     while ($_g1 < $_g) {
         $i = $_g1++;
         $act = $this->modifier->get($i);
         $hdr = $this->header->get($i);
         if ($act === null) {
             $act = "";
         }
         if ($act === "---") {
             $at = -1;
             if ($this->patchInSourceCol->exists($i)) {
                 $at = $this->patchInSourceCol->get($i);
             }
             $mod = new coopy_HighlightPatchUnit();
             $mod->code = $act;
             $mod->rem = true;
             $mod->sourceRow = $at;
             $mod->patchRow = $i;
             $this->cmods->push($mod);
             unset($mod, $at);
         } else {
             if ($act === "+++") {
                 $mod1 = new coopy_HighlightPatchUnit();
                 $mod1->code = $act;
                 $mod1->add = true;
                 $prev = -1;
                 $cont = false;
                 $mod1->sourceRow = -1;
                 if ($this->cmods->length > 0) {
                     $mod1->sourceRow = _hx_array_get($this->cmods, $this->cmods->length - 1)->sourceRow;
                 }
                 if ($mod1->sourceRow !== -1) {
                     $mod1->sourceRowOffset = 1;
                 }
                 $mod1->patchRow = $i;
                 $this->cmods->push($mod1);
                 unset($prev, $mod1, $cont);
             } else {
                 if ($act !== "...") {
                     $at1 = -1;
                     if ($this->patchInSourceCol->exists($i)) {
                         $at1 = $this->patchInSourceCol->get($i);
                     }
                     $mod2 = new coopy_HighlightPatchUnit();
                     $mod2->code = $act;
                     $mod2->patchRow = $i;
                     $mod2->sourceRow = $at1;
                     $this->cmods->push($mod2);
                     unset($mod2, $at1);
                 }
             }
         }
         unset($i, $hdr, $act);
     }
     $at2 = -1;
     $rat = -1;
     $_g11 = 0;
     $_g2 = $this->cmods->length - 1;
     while ($_g11 < $_g2) {
         $i1 = $_g11++;
         $icode = _hx_array_get($this->cmods, $i1)->code;
         if ($icode !== "+++" && $icode !== "---") {
             $at2 = _hx_array_get($this->cmods, $i1)->sourceRow;
         }
         _hx_array_get($this->cmods, $i1 + 1)->sourcePrevRow = $at2;
         $j = $this->cmods->length - 1 - $i1;
         $jcode = _hx_array_get($this->cmods, $j)->code;
         if ($jcode !== "+++" && $jcode !== "---") {
             $rat = _hx_array_get($this->cmods, $j)->sourceRow;
         }
         _hx_array_get($this->cmods, $j - 1)->sourceNextRow = $rat;
         unset($jcode, $j, $icode, $i1);
     }
     $fate = new _hx_array(array());
     $this->permuteColumns();
     if ($this->headerMove !== null) {
         if ($this->colPermutation->length > 0) {
             $_g3 = 0;
             $_g12 = $this->cmods;
             while ($_g3 < $_g12->length) {
                 $mod3 = $_g12[$_g3];
                 ++$_g3;
                 if ($mod3->sourceRow >= 0) {
                     $mod3->sourceRow = $this->colPermutation[$mod3->sourceRow];
                 }
                 unset($mod3);
             }
             if (!$this->useMetaForColumnChanges()) {
                 $this->source->insertOrDeleteColumns($this->colPermutation, $this->colPermutation->length);
             }
         }
     }
     $len = $this->processMods($this->cmods, $fate, $this->source->get_width());
     if (!$this->useMetaForColumnChanges()) {
         $this->source->insertOrDeleteColumns($fate, $len);
         return;
     }
     $changed = false;
     $_g4 = 0;
     $_g13 = $this->cmods;
     while ($_g4 < $_g13->length) {
         $mod4 = $_g13[$_g4];
         ++$_g4;
         if ($mod4->code !== "") {
             $changed = true;
             break;
         }
         unset($mod4);
     }
     if (!$changed) {
         return;
     }
     $columns = new _hx_array(array());
     $target = new haxe_ds_IntMap();
     $inc = array(new _hx_lambda(array(&$at2, &$changed, &$columns, &$fate, &$len, &$rat, &$target), "coopy_HighlightPatch_0"), 'execute');
     $_g14 = 0;
     $_g5 = $fate->length;
     while ($_g14 < $_g5) {
         $i2 = $_g14++;
         $value = call_user_func_array($inc, array($fate[$i2]));
         $target->set($i2, $value);
         unset($value);
         unset($i2);
     }
     $this->needSourceColumns();
     $this->needDestColumns();
     $_g15 = 1;
     $_g6 = $this->patch->get_width();
     while ($_g15 < $_g6) {
         $idx_patch = $_g15++;
         $change = new coopy_ColumnChange();
         $idx_src = null;
         if ($this->patchInSourceCol->exists($idx_patch)) {
             $idx_src = $this->patchInSourceCol->get($idx_patch);
         } else {
             $idx_src = -1;
         }
         $prev_name = null;
         $name = null;
         if ($idx_src !== -1) {
             $prev_name = $this->source->getCell($idx_src, 0);
         }
         if ($this->modifier->get($idx_patch) !== "---") {
             if ($this->header->exists($idx_patch)) {
                 $name = $this->header->get($idx_patch);
             }
         }
         $change->prevName = $prev_name;
         $change->name = $name;
         if ($this->next_meta !== null) {
             if ($this->next_meta->exists($name)) {
                 $change->props = $this->next_meta->get($name);
             }
         }
         $columns->push($change);
         unset($prev_name, $name, $idx_src, $idx_patch, $change);
     }
     $this->meta->alterColumns($columns);
 }
Пример #5
0
 public function getCell($x, $y)
 {
     if ($this->h >= 0) {
         $y = $y - 1;
         if ($y >= 0) {
             $y = $this->id2rid[$y];
         }
     } else {
         if ($y === 0) {
             $y = -1;
         }
     }
     if ($y < 0) {
         $this->getColumns();
         return _hx_array_get($this->columns, $x)->name;
     }
     $row = $this->cache->get($y);
     if ($row === null) {
         $row = new haxe_ds_IntMap();
         $this->getColumns();
         $this->db->beginRow($this->name, $y, $this->columnNames);
         while ($this->db->read()) {
             $_g1 = 0;
             $_g = $this->get_width();
             while ($_g1 < $_g) {
                 $i = $_g1++;
                 $v = $this->db->get($i);
                 $row->set($i, $v);
                 $v;
                 unset($v);
                 unset($i);
             }
             unset($_g1, $_g);
         }
         $this->db->end();
         $this->cache->set($y, $row);
         $row;
     }
     $this1 = $this->cache->get($y);
     return $this1->get($x);
 }