TraceWizard.Diff.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)
        {
            // Debug.Write(2, "LCS", String.Format("Analyse the box: A[{0}-{1}] to B[{2}-{3}]", LowerA, UpperA, LowerB, UpperB));

            // 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);
                // Debug.Write(2, "MiddleSnakeData", String.Format("{0},{1}", smsrd.x, smsrd.y));

                // The path is from LowerX to (x,y) and (x,y) to UpperX
                LCS(DataA, LowerA, smsrd.x, DataB, LowerB, smsrd.y, DownVector, UpVector);
                LCS(DataA, smsrd.x, UpperA, DataB, smsrd.y, UpperB, DownVector, UpVector);  // 2002.09.20: no need for 2 points 
            }
        } // LCS()