Git.Core.Diff.LCS C# (CSharp) Method

LCS() private static method

This is the divide-and-conquer implementation of the longes common-subsequence (LCS) algorithm. The published algorithm passes recursively parts of the A and B sequences. To avoid copying these arrays the lower and upper bounds are passed while the sequences stay constant.
private static LCS ( DiffData DataA, int LowerA, int UpperA, DiffData DataB, int LowerB, int UpperB, int DownVector, int UpVector ) : void
DataA DiffData sequence A
LowerA int lower bound of the actual range in DataA
UpperA int upper bound of the actual range in DataA (exclusive)
DataB DiffData sequence B
LowerB int lower bound of the actual range in DataB
UpperB int upper bound of the actual range in DataB (exclusive)
DownVector int a vector for the (0,0) to (x,y) search. Passed as a parameter for speed reasons.
UpVector int a vector for the (u,v) to (N,M) search. Passed as a parameter for speed reasons.
return void
        private static void LCS(DiffData DataA, int LowerA, int UpperA, DiffData DataB, int LowerB, int UpperB, int[] DownVector, int[] UpVector)
        {
            // Fast walkthrough equal lines at the start
            while (LowerA < UpperA && LowerB < UpperB && DataA.data[LowerA] == DataB.data[LowerB]) {
                LowerA++; LowerB++;
            }

            // Fast walkthrough equal lines at the end
            while (LowerA < UpperA && LowerB < UpperB && DataA.data[UpperA - 1] == DataB.data[UpperB - 1]) {
                --UpperA; --UpperB;
            }

            if (LowerA == UpperA) {
                // mark as inserted lines.
                while (LowerB < UpperB)
                    DataB.modified[LowerB++] = true;

            } else if (LowerB == UpperB) {
                // mark as deleted lines.
                while (LowerA < UpperA)
                    DataA.modified[LowerA++] = true;

            } else {
                // Find the middle snakea and length of an optimal path for A and B
                SMSRD smsrd = SMS(DataA, LowerA, UpperA, DataB, LowerB, UpperB, DownVector, UpVector);

                LCS(DataA, LowerA, smsrd.x, DataB, LowerB, smsrd.y, DownVector, UpVector);
                LCS(DataA, smsrd.x, UpperA, DataB, smsrd.y, UpperB, DownVector, UpVector);
            }
        }