Calculate the edit distance matrix.

@param array $olds the olds
@param array $news the news
@param array $dist the edit distance matrix

@return null|array the edit progresses
490032
private function calculateProgresses(array $olds, array $news, array $dist): ?array
    {
        if (!$this->calculateProgresses) {
            return null;
        }

        // raw edit progresses
        $rawProgresses = $this->calculateRawProgresses($dist);

        // resolve raw edit progresses
        $progresses = $this->resolveRawProgresses($rawProgresses);

        // merge neighbor progresses
        if ($this->progressOptions & self::PROGRESS_MERGE_NEIGHBOR) {
            $progresses = $this->mergeNeighborProgresses($progresses);
        }

        // merge progresses like patches
        if ($this->progressOptions & self::PROGRESS_PATCH_MODE) {
            $progresses = $this->makeProgressesPatch($olds, $news, $progresses);
        }

        // remove "COPY" operations
        if ($this->progressOptions & self::PROGRESS_NO_COPY) {
            $progresses = $this->removeCopyProgresses($progresses);
        }

        // operation name as string
        if ($this->progressOptions & self::PROGRESS_OP_AS_STRING) {
            $progresses = $this->stringifyOperations($progresses);
        }

        return $progresses;
    }
52028
public function doDiff( array $oldValues, array $newValues ): array {
		$newSet = $this->arrayDiffAssoc( $newValues, $oldValues );
		$oldSet = $this->arrayDiffAssoc( $oldValues, $newValues );

		$diffSet = [];

		foreach ( $this->getAllKeys( $oldSet, $newSet ) as $key ) {
			$diffOp = $this->getDiffOpForElement( $key, $oldSet, $newSet );

			if ( $diffOp !== null ) {
				$diffSet[$key] = $diffOp;
			}
		}

		return $diffSet;
	}
1327490
public function compareTrees(array $previous, array $latest)
    {
        $sum = array_merge(
            array_keys($previous),
            array_keys($latest)
        );

        $sum = array_filter($sum, 'is_string');
        $sum = array_unique($sum);
        asort($sum);

        foreach ($sum as $key) {
            $old = null;
            if (isset( $previous[$key] )) {
                $old = $previous[$key];
            }

            $new = null;
            if (isset( $latest[$key] )) {
                $new = $latest[$key];
            }

            $this->handleNode($old, $new);

            if ($old && $new) {
                foreach ($old->getSubNodeNames() as $subNode) {
                    if ( ! is_array($old->$subNode)) {
                        continue;
                    }

                    $this->compareTrees($old->$subNode, $new->$subNode);
                }
            }
        }

        return null;
    }
22044
protected function formatNamespace(array $new, array $old)
    {
        if (isset($new['namespace']) && isset($old['namespace'])) {
            return trim($old['namespace'], '\\').'\\'.trim($new['namespace'], '\\');
        } elseif (isset($new['namespace'])) {
            return trim($new['namespace'], '\\');
        }

        return array_get($old, 'namespace');
    }
1354343
function lcs()
    {
        $lcs = 0;
        foreach ($this->_edits as $edit) {
            if (is_a($edit, 'Text_Diff_Op_copy')) {
                $lcs += count($edit->orig);
            }
        }
        return $lcs;
    }
1343980
public static function merge($new, $old)
    {
        if (isset($new['domain'])) {
            unset($old['domain']);
        }

        $new = array_merge(static::formatAs($new, $old), [
            'namespace' => static::formatNamespace($new, $old),
            'prefix' => static::formatPrefix($new, $old),
            'where' => static::formatWhere($new, $old),
        ]);

        return array_merge_recursive(Arr::except(
            $old, ['namespace', 'prefix', 'where', 'as']
        ), $new);
    }
218875
private static function distanceRadians( $lat1,  $lng1,  $lat2,  $lng2) {
        return MathUtil::arcHav(MathUtil::havDistance($lat1, $lat2, $lng1 - $lng2));
    }
34626
protected function auditUpdatedAttributes(array &$old, array &$new)
    {
        foreach ($this->getDirty() as $attribute => $value) {
            if ($this->isAttributeAuditable($attribute)) {
                $old[$attribute] = array_get($this->original, $attribute);
                $new[$attribute] = array_get($this->attributes, $attribute);
            }
        }
    }
547578
function getEditDistance(values) {
  if (values.length === 2) {
    console.log(dice(values[0], values[1]) || 0)
  } else {
    process.stderr.write(help())
    process.exit(1)
  }
}
712283
public function edit( $oldItem, $newItem )
	{
		$index	= $this->getIndex( $oldItem );
		$this->list[$index]	= $newItem;
		return $this->write();
	}
493023
protected function processExistingLemmas($family, array $old_lemmas = [], array $new_lemmas = [])
    {
        // Get existing lemmas
        $lemmas = array_intersect_key($old_lemmas, $new_lemmas);

        if (count($lemmas) > 0) {
            // Sort lemmas by key
            ksort($lemmas);

            if ($this->option('verbose')) {
                $this->line("            " . count($lemmas) . " already translated strings");
            }

            foreach ($lemmas as $key => $value) {
                Arr::set(
                    $this->final_lemmas, $key, $value
                );
            }

            return true;
        }

        return false;
    }
823769
function substrings( $sub, $old, $new )
    {
        $matrix = $sub['lengthMatrix'];
        $val = $sub['maxLength'];
        $row = $sub['maxRow'];
        $col = $sub['maxCol'];

        if ( $val == 0 )
        {
            //No common substrings were found
            return array();
        }

        $rows = count( $old );
        $cols = count( $new );

        $lcsOffsets = $this->findLongestSubstringOffsets( $sub );
        $lcsPlacement = $this->substringPlacement( $lcsOffsets['newStart'], $lcsOffsets['newEnd'], $cols );

        $substringSet = array();

        $substringArray = $this->traceSubstring( $row, $col, $matrix, $val, $new );
        $substring = $substringArray['substring'];
        unset( $substringArray );
        $substringSet[] = array_reverse( $substring, true );
        $substring = array();

        //Get more text
        if ( $lcsPlacement['hasTextLeft'] )
        {
            $row = $lcsOffsets['oldStart'];
            $col = $lcsOffsets['newStart'];

            if ( $row != 0 )
            {
                $row--;
            }

            if ( $col != 0 )
            {
                $col--;
            }

            $done = false;
            $info = true;
            $prevRowUsed = -1;

            while ( !$done && $info )
            {
                if ( $prevRowUsed == $row )
                {
                    $done = true;
                    continue;
                }

                $info = $this->localSubstring( 'left', $row, $col, $rows, $cols, $matrix );
                $prevRowUsed = $row;
                if ( $info )
                {
                    $substringArray = $this->traceSubstring( $info['remainRow'], $info['remainCol'], $matrix, $info['remainMax'], $new );
                    $substring = $substringArray['substring'];
                    array_unshift( $substringSet, array_reverse( $substring, true ) );
                    $substring = array();

                    if ( $info['remainCol'] == 0 || $substringArray['lastCol'] == 0 )
                    {
                        $done = true;
                    }
                    else
                    {
                        $row = $substringArray['lastRow'];
                        $col = $substringArray['lastCol'];

                        if ( $row != 0 )
                        {
                            $row--;
                        }
                        if ( $col != 0 )
                        {
                            $col--;
                        }
                    }
                    unset( $substringArray );
                }
            }
        }


        if ( $lcsPlacement['hasTextRight'] )
        {
            //reset search location in matrix
            $row = $sub['maxRow'];
            $col = $sub['maxCol'];

            if ( $row != $rows-1 )
            {
                $row++;
            }

            if ( $col != $cols-1 )
            {
                $col++;
            }

            $done = false;
            $info = true;
            $prevRowUsed = -1;

            while( !$done && $info )
            {
                if ( $prevRowUsed == $row )
                {
                    $done = true;
                    continue;
                }
                $info = $this->localSubstring( 'right', $row, $col, $rows, $cols, $matrix );
                $prevRowUsed = $row;
                if ( $info )
                {
                    $substringArray = $this->traceSubstring( $info['remainRow'], $info['remainCol'], $matrix, $info['remainMax'], $new );
                    $substring = $substringArray['substring'];
                    $substringSet[] = array_reverse( $substring, true );
                    $substring = array();

                    if ( $info['remainCol'] == $cols-1 || $substringArray['lastRow'] == $cols-1 )
                    {
                        $done = true;
                    }
                    else
                    {
                        $row = $info['remainRow'];
                        $col = $info['remainCol'];

                        if ( $row != $rows-1 )
                        {
                            $row++;
                        }

                        if ( $col != $cols-1 )
                        {
                            $col++;
                        }
                    }
                    unset( $substringArray );
                }
            }
        }
        return $substringSet;
    }
1004420
function start_symbol( $newss = null ){
		$oldss = $this->goal;
		if( ! is_null($newss) ){
			$this->goal = $newss;
			// special wrapper rule
			$this->rules[ -2 ] = array( P_GOAL, array( $newss, P_EOF ) );
			$this->rebuild_index();
		}
		return $oldss;
	}
106403
private function diffRecords($old, $new)
	{
		$diff = Set::diff($old, $new);
		$formatted = array();

		foreach ($diff as $key => $value) {
			if (!isset($old[$key]) || !isset($new[$key])) {
				continue;
			}

			$formatted[$key] = array('old' => $old[$key], 'new' => $new[$key]);
		}

		return $formatted;
	}
166645
public static function diff($old, $new): array
    {
        if (!is_array($old)) {
            $old = preg_split("/[\s]+/", $old);
        }
        if (!is_array($new)) {
            $new = preg_split("/[\s]+/", $new);
        }

        $oldNormalized = array_map(function (string $str) {
            return strtoupper(self::removeAccents($str));
        }, $old);
        $newNormalized = array_map(function (string $str) {
            return strtoupper(self::removeAccents($str));
        }, $new);

        $matrix = [];
        $maxlen = 0;

        foreach ($oldNormalized as $oindex => $ovalue) {
            $nkeys = array_keys($newNormalized, $ovalue);
            foreach ($nkeys as $nindex) {
                $matrix[$oindex][$nindex] = (isset($matrix[$oindex - 1][$nindex - 1]) ? $matrix[$oindex - 1][$nindex - 1] + 1 : 1);

                if ($matrix[$oindex][$nindex] > $maxlen) {
                    $maxlen = $matrix[$oindex][$nindex];
                    $omax = $oindex + 1 - $maxlen;
                    $nmax = $nindex + 1 - $maxlen;
                }
            }
        }

        if ($maxlen == 0) {
            return [
                [
                    'deleted'  => $old,
                    'inserted' => $new,
                ],
            ];
        }

        return array_merge(
            self::diff(array_slice($old, 0, $omax), array_slice($new, 0, $nmax)),
            array_slice($new, $nmax, $maxlen),
            self::diff(array_slice($old, $omax + $maxlen), array_slice($new, $nmax + $maxlen))
        );
    }
426967
protected function calculateRequestDiff($locale, $domain, array $catalogs) {
		$domain = array_flip((array) $domain);
		$locale = array_flip((array) $locale);
		
		$diffLocale = array_diff_key($locale, $catalogs);
		$diffDomain = empty($diffLocale) ? [] : $domain;
		
		foreach ($catalogs as $localeId => $catalog) {
			$diff = array_diff_key($domain, $catalog);
			
			if (! empty($diff)) {
				$diffDomain           += $diff;
				$diffLocale[$localeId] = true;
			}
		}
		
		if (empty($diffLocale)) {
			return;
		}
		
		return [
			$this->normalizeRequestDiff($diffLocale),
			$this->normalizeRequestDiff($diffDomain)
		];
	}
745596
public function diffHtml($old, $new, $output = 'array')
    {
        if (!in_array($output, ['array', 'string'])) {
            throw new \RuntimeException(
                sprintf('Unknown output type "%s"', $output)
            );
        }

        $ret = '';
        $arr = [
            'old' => '',
            'new' => '',
        ];

        $diff = $this->diff(preg_split("/[\s]+/", $old), preg_split("/[\s]+/", $new));

        //die(print_r($diff));
        foreach ($diff as $k) {
            if (is_array($k)) {
                $deletions  = !empty($k['d']) ? '<del>'.implode(' ', $k['d']).'</del>' : '';
                $insertions = !empty($k['i']) ? '<ins>'.implode(' ', $k['i']).'</ins>' : '';
                $deletions  = $deletions.(!empty($deletions) ? ' ' : '');
                $insertions = $insertions.(!empty($insertions) ? ' ' : '');
                $ret .= trim($deletions).$insertions;
                $arr['old'] .= $deletions;
                $arr['new'] .= $insertions;
            } else {
                // No differences
                $str = $k.' ';
                $ret .= $str;
                $arr['old'] .= $str;
                $arr['new'] .= $str;
            }
        }

        // cleanup
        $ret        = trim(ltrim($ret));
        $arr['old'] = trim(ltrim($arr['old']));
        $arr['new'] = trim(ltrim($arr['new']));

        return ($output === 'string') ? $ret : $arr;
    }