Exemplo n.º 1
0
 /**
  * find the longest_common_subarray between $achars and $bchars
  * requirement: a subarray must have at least a third of the
  * of $achars and $bchars (or whatever percentage the setting of 
  * $divisor will yield) 
  */
 public static function longest_common_subarray($achars, $bchars)
 {
     $alen = count($achars);
     $blen = count($bchars);
     if ($alen > $blen) {
         //swap
         $cchars = $achars;
         $achars = $bchars;
         $bchars = $cchars;
         $clen = $alen;
         $alen = $blen;
         $blen = $clen;
     }
     $binverted = StringDiff::array_invert($bchars);
     $longest_common_subarray = array();
     $idmap = StringDiff::getIDMap($achars, $alen, $binverted);
     $commonarrays = StringDiff::getCommonArrays($idmap, $alen, $achars);
     if (empty($commonarrays)) {
         return array();
     }
     $longestarray = StringDiff::getLongestCommonArray($commonarrays);
     if (count($longestarray) < ceil($alen / StringDiff::$divisor) && count($longestarray) < ceil($blen / StringDiff::$divisor)) {
         return array();
         // overlap is too short
     }
     return $longestarray;
     // long enough
 }
Exemplo n.º 2
0
	function diffHighlight() {
		return StringDiff::toHTML($this->prevalue, $this->postvalue);
	}