atrsimilar_lcs_matrix

Versions
6.1
atrsimilar_lcs_matrix($tokens, $length)

Compute an LCS matrix.

▾ 1 function calls atrsimilar_lcs_matrix()

atrsimilar_diff in atr/modules/atrsimilar/includes/atrsimilar.review.inc
Compute the differences between two strings.

Code

atr/modules/atrsimilar/includes/atrsimilar.review.inc, line 176

<?php
function atrsimilar_lcs_matrix($tokens, $length) {
  $matrix = array();

  for ($i = 0; $i < $length[0]; $i++) {
    for ($j = 0; $j < $length[1]; $j++) {
      if ($tokens[0][$i] === $tokens[1][$j]) {
        $matrix[$i][$j] = (isset($matrix[$i - 1][$j - 1]) ? $matrix[$i - 1][$j - 1] : 0) + 1;
      }
      else {
        $matrix[$i][$j] = max(
          isset($matrix[$i][$j - 1]) ? $matrix[$i][$j - 1] : 0,
          isset($matrix[$i - 1][$j]) ? $matrix[$i - 1][$j] : 0
        );
      }
    }
  }

  return $matrix;
}
?>