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); } }
/** * @param int $a * @param int $b * @param int $c * @param int $x * @return int */ public static function quadEquation($a, $b, $c, $x) { return $a * Math::pow($x, 2) + $b * $x + $c; }
$arr = array('fdjiefwf', '123'); Funt::map($arr, function ($k, $v) { echo "{$k} -> {$v} \n"; }); Funt::map($arr, lambda('$k, $v -> print "$k ==> $v \\n"')); $str = "abcdefg"; Funt::map($str, function ($ch) { echo "{$ch} \n"; }); $arr = array(1, 2, 3, 4, 5); echo Funt::reduce(function ($r, $k, $v) { return $r + $v; }, 1, $arr) . "\n"; echo Math::add(1, 2, 3, 4, 5, 6) . "\n"; echo Math::mul(1, 2, 3, 4, 5, 6) . "\n"; echo Math::pow(2, 3, 2) . "\n"; echo 2 ** 3 ** 2 . "\n"; function abc() { } var_dump('abc') . "\n"; // PHP不支持“惰性特征” // $arr = array(1/0, 3, 4); // var_dump(count($arr)); // PHP的闭包“惰性特征” $arr = function () { return array(1 / 0); }; // 使用PHP的yeild协同机制,可以实现类似nodejs的事件机制。 /* 函数式编程通用方法语义说明: