/// <summary> /// The get longest source match. /// </summary> /// <param name="curItem"> /// The cur item. /// </param> /// <param name="destIndex"> /// The dest index. /// </param> /// <param name="destEnd"> /// The dest end. /// </param> /// <param name="sourceStart"> /// The source start. /// </param> /// <param name="sourceEnd"> /// The source end. /// </param> private void GetLongestSourceMatch( DiffState curItem, int destIndex, int destEnd, int sourceStart, int sourceEnd) { var maxDestLength = (destEnd - destIndex) + 1; var curBestLength = 0; var curBestIndex = -1; for (var sourceIndex = sourceStart; sourceIndex <= sourceEnd; sourceIndex++) { var maxLength = Math.Min(maxDestLength, (sourceEnd - sourceIndex) + 1); if (maxLength <= curBestLength) { // No chance to find a longer one any more break; } var curLength = this.GetSourceMatchLength(destIndex, sourceIndex, maxLength); if (curLength > curBestLength) { // This is the best match so far curBestIndex = sourceIndex; curBestLength = curLength; } // jump over the match sourceIndex += curBestLength; } if (curBestIndex == -1) { curItem.SetNoMatch(); } else { curItem.SetMatch(curBestIndex, curBestLength); } }
private void GetLongestSourceMatch(DiffState curItem, int destIndex,int destEnd, int sourceStart,int sourceEnd) { int maxDestLength = (destEnd - destIndex) + 1; int curLength = 0; int curBestLength = 0; int curBestIndex = -1; int maxLength = 0; for (int sourceIndex = sourceStart; sourceIndex <= sourceEnd; sourceIndex++) { maxLength = Math.Min(maxDestLength,(sourceEnd - sourceIndex) + 1); if (maxLength <= curBestLength) { //No chance to find a longer one any more break; } curLength = GetSourceMatchLength(destIndex,sourceIndex,maxLength); if (curLength > curBestLength) { //This is the best match so far curBestIndex = sourceIndex; curBestLength = curLength; } //jump over the match sourceIndex += curBestLength; } //DiffState cur = _stateList.GetByIndex(destIndex); if (curBestIndex == -1) { curItem.SetNoMatch(); } else { curItem.SetMatch(curBestIndex, curBestLength); } }
private void GetLongestSourceMatch(DiffState curItem, int destIndex, int destEnd, int sourceStart, int sourceEnd) { int maxDestLength = (destEnd - destIndex) + 1;//新版本最大行数 int curLength = 0; int curBestLength = 0; int curBestIndex = -1; int maxLength = 0; for (int sourceIndex = sourceStart; sourceIndex <= sourceEnd; sourceIndex++) { maxLength = Math.Min(maxDestLength, (sourceEnd - sourceIndex) + 1); if (maxLength <= curBestLength) { //No chance to find a longer one any more break; } //比如当前新文件的当前行为第1行,1-9行相同Unchanged,第10行不匹配Different,返回 10-0 = 10 相同数目...... curLength = GetSourceMatchLength(destIndex, sourceIndex, maxLength); if (curLength > curBestLength) { //This is the best match so far curBestIndex = sourceIndex; curBestLength = curLength;//当前有10行匹配相同 } //jump over the match,跳出匹配项 sourceIndex += curBestLength; //将索引增加匹配的个数,比较下一行 } //设置当前行的状态: if (curBestIndex == -1)//如果从第一行找到最后一行,没有相同项目。设置每个行为不匹配状态 { curItem.SetNoMatch(); } else { curItem.SetMatch(curBestIndex, curBestLength); } }