public List <ItemPosition> GetLongestCommonSubsequence(string[] file1, string[] file2) { _file1 = file1; _file2 = file2; _minValue = Math.Min(_file1.Length, _file2.Length); _maxValue = Math.Max(_file1.Length, _file2.Length); _matchList = new List <List <int> >(); _threshArray = new List <int>(); _linksCorrect = new ItemPosition[_minValue + 1]; _linksCorrect[0] = new ItemPosition { IndexFile1 = -1, IndexFile2 = -1 }; SetMatchList(); InitializeThresh(); ComputeThresh(); List <ItemPosition> result = _linksCorrect.ToList(); result.RemoveAll(item => item == null); List <ItemPosition> l = new List <ItemPosition>(); var lastItem = result.LastOrDefault(); while (lastItem != null) { l.Add(lastItem); lastItem = lastItem.LinkPrevious; } return(l); }
private void ComputeThresh() { for (int i = 0; i < _matchList.Count; i++) { foreach (var item in _matchList[i]) { for (int k = 0; k < _threshArray.Count - 2; k++) { if (_threshArray[k] < item + 1 && _threshArray[k + 1] >= item + 1) { if (_threshArray[k + 1] > item + 1) { _threshArray[k + 1] = item + 1; _linksCorrect[k + 1] = new ItemPosition { IndexFile1 = i, IndexFile2 = item, LinkPrevious = _linksCorrect[k] }; } break; } } } } }