Beispiel #1
0
        /// <summary>
        /// Scan the tables of which lines are inserted and deleted,
        /// producing an edit script in forward order.  
        /// </summary>
        private static Difference[] CreateDiffs(DiffData DataA, DiffData DataB)
        {
            ArrayList a = new ArrayList();
            Difference aItem;
            Difference[] result;

            int StartA, StartB;
            int LineA, LineB;

            LineA = 0;
            LineB = 0;
            while (LineA < DataA.Length || LineB < DataB.Length)
            {
                if ((LineA < DataA.Length) && (!DataA.modified[LineA])
                  && (LineB < DataB.Length) && (!DataB.modified[LineB]))
                {
                    // equal lines
                    LineA++;
                    LineB++;

                }
                else
                {
                    // maybe deleted and/or inserted lines
                    StartA = LineA;
                    StartB = LineB;

                    while (LineA < DataA.Length && (LineB >= DataB.Length || DataA.modified[LineA]))
                        // while (LineA < DataA.Length && DataA.modified[LineA])
                        LineA++;

                    while (LineB < DataB.Length && (LineA >= DataA.Length || DataB.modified[LineB]))
                        // while (LineB < DataB.Length && DataB.modified[LineB])
                        LineB++;

                    if ((StartA < LineA) || (StartB < LineB))
                    {
                        // store a new difference-item
                        aItem = new Difference();
                        aItem.startA = StartA;
                        aItem.startB = StartB;
                        aItem.countA = LineA - StartA;
                        aItem.countB = LineB - StartB;
                        a.Add(aItem);
                    } // if
                } // if
            } // while

            result = new Difference[a.Count];
            a.CopyTo(result);

            return (result);
        }
Beispiel #2
0
        public void ClearDiff()
        {
            if (diffData == null)
            {
                return;
            }

            for (var line = diffData.LineCompare.Count - 1; line >= 0; --line)
            {
                if (diffData.LineCompare[line] == LCS.MatchType.Gap)
                {
                    lineOffset.RemoveAt(line);
                    endingOffset.RemoveAt(line);
                }
            }

            diffData = null;
        }
Beispiel #3
0
        public Diff(int nIndex, int rorl, DiffData pDData)
        {
            if (null == pDData)
            {
                return;
            }
            Index       = nIndex;
            RightOrLeft = rorl;

            ID       = pDData.ID;
            bKnocked = false;
            PosX     = pDData.PosX;
            PosY     = pDData.PosY;
            RightX   = pDData.RightX;
            RightY   = pDData.RightY;
            LeftX    = pDData.LeftX;
            LeftY    = pDData.LeftY;
        }
        }// Sms

        /// <summary>
        /// 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.
        /// </summary>
        /// <param name="DataA">sequence A</param>
        /// <param name="LowerA">lower bound of the actual range in DataA</param>
        /// <param name="UpperA">upper bound of the actual range in DataA (exclusive)</param>
        /// <param name="DataB">sequence B</param>
        /// <param name="LowerB">lower bound of the actual range in DataB</param>
        /// <param name="UpperB">upper bound of the actual range in DataB (exclusive)</param>
        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) ot 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()
        public static List <DiffData>[] Diff(List <string> src, List <string> dst)
        {
            List <DiffData>[] diffResult = new List <DiffData> [3];
            List <DiffData>   diffRes    = new List <DiffData>();
            List <DiffData>   diffSrc    = new List <DiffData>();
            List <DiffData>   diffDst    = new List <DiffData>();
            var res    = ShortestEditScript(src, dst);
            int index1 = 0;
            int index2 = 0;

            for (int i = 0; i < res.Count; i++)
            {
                var oper = res[i];
                switch (oper)
                {
                case Operation.Add:
                    DiffData diff = new DiffData(dst[index2], Add, index2.ToString());
                    diffRes.Add(diff);
                    diffDst.Add(diff);
                    index2++;
                    break;

                case Operation.Move:
                    DiffData diff2 = new DiffData(dst[index2], Move, index2.ToString());
                    diffRes.Add(diff2);
                    diffDst.Add(diff2);
                    diffSrc.Add(new DiffData(src[index1], Move, index1.ToString()));
                    index2++;
                    index1++;
                    break;

                case Operation.Delete:
                    DiffData diff3 = new DiffData(src[index1], Del, index1.ToString());
                    diffRes.Add(diff3);
                    diffSrc.Add(diff3);
                    index1++;
                    break;
                }
            }
            diffResult[0] = diffRes;
            diffResult[1] = diffSrc;
            diffResult[2] = diffDst;
            return(diffResult);
        }
Beispiel #6
0
    } // DiffText


    /// <summary>
    /// If a sequence of modified lines starts with a line that contains the same content
    /// as the line that appends the changes, the difference sequence is modified so that the
    /// appended line and not the starting line is marked as modified.
    /// This leads to more readable diff sequences when comparing text files.
    /// </summary>
    /// <param name="Data">A Diff data buffer containing the identified changes.</param>
    private static void Optimize(DiffData Data) {
      int StartPos, EndPos;

      StartPos = 0;
      while (StartPos < Data.Length) {
        while ((StartPos < Data.Length) && (Data.modified[StartPos] == false))
          StartPos++;
        EndPos = StartPos;
        while ((EndPos < Data.Length) && (Data.modified[EndPos] == true))
          EndPos++;

        if ((EndPos < Data.Length) && (Data.data[StartPos] == Data.data[EndPos])) {
          Data.modified[StartPos] = false;
          Data.modified[EndPos] = true;
        } else {
          StartPos = EndPos;
        } // if
      } // while
    } // Optimize
    } // SMS

    /// <summary>
    /// 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.
    /// </summary>
    /// <param name="DataA">sequence A</param>
    /// <param name="LowerA">lower bound of the actual range in DataA</param>
    /// <param name="UpperA">upper bound of the actual range in DataA (exclusive)</param>
    /// <param name="DataB">sequence B</param>
    /// <param name="LowerB">lower bound of the actual range in DataB</param>
    /// <param name="UpperB">upper bound of the actual range in DataB (exclusive)</param>
    /// <param name="DownVector">a vector for the (0,0) to (x,y) search. Passed as a parameter for speed reasons.</param>
    /// <param name="UpVector">a vector for the (u,v) to (N,M) search. Passed as a parameter for speed reasons.</param>
    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()
Beispiel #8
0
    } // DiffText

    /// <summary>
    ///     Find the difference in 2 arrays of integers.
    /// </summary>
    /// <param name="arrayA">A-version of the numbers (usually the old one)</param>
    /// <param name="arrayB">B-version of the numbers (usually the new one)</param>
    /// <returns>Returns a array of Items that describe the differences.</returns>
    public static Item[] DiffInt(int[] arrayA, int[] arrayB)
    {
        // The A-Version of the data (original data) to be compared.
        var dataA = new DiffData(arrayA);

        // The B-Version of the data (modified data) to be compared.
        var dataB = new DiffData(arrayB);

        var max = dataA.Length + dataB.Length + 1;

        // vector for the (0,0) to (x,y) search
        var downVector = new int[(2 * max) + 2];

        // vector for the (u,v) to (N,M) search
        var upVector = new int[(2 * max) + 2];

        Lcs(dataA, 0, dataA.Length, dataB, 0, dataB.Length, downVector, upVector);
        return(CreateDiffs(dataA, dataB));
    } // Diff
Beispiel #9
0
        public static DiffStringItem[] DiffStringLines(string[] dataA, string[] dataB, SpacesAction spacesAction)
        {
            IEqualityComparer <string> comparer = null;

            if (spacesAction == SpacesAction.IgnoreChange)
            {
                comparer = new IgnoreComparer();
            }
            else if (spacesAction == SpacesAction.IgnoreAll)
            {
                comparer = new IgnoreAllComparer();
            }

            var lineTable = new Dictionary <string, int>(comparer);
            var diffDataA = new DiffData(GetIndexList(dataA, lineTable));
            var diffDataB = new DiffData(GetIndexList(dataB, lineTable));

            return(CreateStringDiffs(GetDiff(diffDataA, diffDataB), dataA, dataB));
        }
Beispiel #10
0
        /// <summary>
        /// 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.
        /// </summary>
        /// <param name="dataLeft">sequence A</param>
        /// <param name="lowerLeft">lower bound of the actual range in DataA</param>
        /// <param name="upperLeft">upper bound of the actual range in DataA (exclusive)</param>
        /// <param name="dataRight">sequence B</param>
        /// <param name="lowerRight">lower bound of the actual range in DataB</param>
        /// <param name="upperRight">upper bound of the actual range in DataB (exclusive)</param>
        private static void LCS(DiffData dataLeft, int lowerLeft, int upperLeft, DiffData dataRight, int lowerRight, int upperRight)
        {
            // Fast walkthrough equal lines at the start
            while (lowerLeft < upperLeft && lowerRight < upperRight && dataLeft.Data[lowerLeft] == dataRight.Data[lowerRight])
            {
                lowerLeft++;
                lowerRight++;
            }

            // Fast walkthrough equal lines at the end
            while (lowerLeft < upperLeft && lowerRight < upperRight && dataLeft.Data[upperLeft - 1] == dataRight.Data[upperRight - 1])
            {
                --upperLeft;
                --upperRight;
            }

            if (lowerLeft == upperLeft)
            {
                // mark as inserted lines.
                while (lowerRight < upperRight)
                {
                    dataRight.Modified[lowerRight++] = true;
                }
            }
            else if (lowerRight == upperRight)
            {
                // mark as deleted lines.
                while (lowerLeft < upperLeft)
                {
                    dataLeft.Modified[lowerLeft++] = true;
                }
            }
            else
            {
                // Find the middle snakea and length of an optimal path for A and B
                var smsrd = SMS(dataLeft, lowerLeft, upperLeft, dataRight, lowerRight, upperRight);

                // The path is from LowerX to (x,y) and (x,y) ot UpperX
                LCS(dataLeft, lowerLeft, smsrd._x, dataRight, lowerRight, smsrd._y);
                LCS(dataLeft, smsrd._x, upperLeft, dataRight, smsrd._y, upperRight);  // 2002.09.20: no need for 2 points
            }
        }
Beispiel #11
0
 // Longest common substring algorithm
 static void _lcs(DiffData data_left, int lower_left, int upper_left, DiffData data_right, int lower_right, int upper_right, int[] down_vector, int[] up_vector)
 {
     // Fast walkthrough equal lines at the start
     while (lower_left < upper_left &&
            lower_right < upper_right &&
            data_left.data[lower_left] == data_right.data[lower_right])
     {
         lower_left++; lower_right++;
     }
     // Fast walkthrough equal lines at the end
     while (lower_left < upper_left &&
            lower_right < upper_right &&
            data_left.data[upper_left - 1] == data_right.data[upper_right - 1])
     {
         --upper_left; --upper_right;
     }
     if (lower_left == upper_left)
     {
         // mark as inserted lines.
         while (lower_right < upper_right)
         {
             data_right.modified[lower_right++] = true;
         }
     }
     else if (lower_right == upper_right)
     {
         // mark as deleted lines.
         while (lower_left < upper_left)
         {
             data_left.modified[lower_left++] = true;
         }
     }
     else
     {
         // Find the middle snake and length of an optimal path for A and B
         var smsrd = _sms(data_left, lower_left, upper_left, data_right, lower_right, upper_right, down_vector, up_vector);
         // The path is from LowerX to (x,y) and (x,y) to UpperX
         _lcs(data_left, lower_left, smsrd.x, data_right, lower_right, smsrd.y, down_vector, up_vector);
         _lcs(data_left, smsrd.x, upper_left, data_right, smsrd.y, upper_right, down_vector, up_vector);
     }
 }
        void LoadDiffs()
        {
            DiffData ddata = GetDiffData();

            if (ddata.diffRunning)
            {
                return;
            }

            // Diff not yet requested. Do it now.
            ddata.diffRunning = true;

            // Run the diff in a separate thread and update the tree when done
            ThreadPool.QueueUserWorkItem(
                delegate
            {
                ddata.diffException = null;
                try
                {
                    ddata.difs = DiffLoader(changeSet.BaseLocalPath);
                }
                catch (Exception ex)
                {
                    ddata.diffException = ex;
                }
                finally
                {
                    ddata.diffRequested = true;
                    ddata.diffRunning   = false;
                    if (null != DiffDataLoaded)
                    {
                        Gtk.Application.Invoke(delegate
                        {
                            DiffDataLoaded(ddata);
                            DiffDataLoaded = null;
                        });
                    }
                }
            }
                );
        }
    public bool SetDiffResults(DiffData InData)
    {
        if (InData.JudgeNameId == -1)
        {
            return(false);
        }

        ResultsData rd          = TournamentData.FindResultsData(InData.Division, InData.Round, InData.Pool);
        int         ResultIndex = -1;

        for (int i = 0; i < rd.DiffJudgeIds.Count; ++i)
        {
            if (InData.JudgeNameId == rd.DiffJudgeIds[i])
            {
                ResultIndex = i;
                break;
            }
        }

        bool bNewScore = false;

        if (ResultIndex >= 0)
        {
            for (int DataIndex = 0; DataIndex <= ResultIndex; ++DataIndex)
            {
                if (DataIndex >= DiffResults.Count)
                {
                    DiffResults.Add(new DiffData());
                }
            }

            if (!DiffResults[ResultIndex].IsValid())
            {
                bNewScore = true;
            }

            DiffResults[ResultIndex] = InData;
        }

        return(bNewScore);
    }
Beispiel #14
0
        static DiffItem[] CreateDiffs(DiffData diffDataA, DiffData diffDataB)
        {
            var      list = new List <DiffItem>();
            DiffItem item;
            int      startA, startB;
            int      lineA, lineB;

            lineA = 0;
            lineB = 0;
            while (lineA < diffDataA.Length || lineB < diffDataB.Length)
            {
                if ((lineA < diffDataA.Length) && (!diffDataA.modified[lineA]) && (lineB < diffDataB.Length) && (!diffDataB.modified[lineB]))
                {
                    lineA++;
                    lineB++;
                }
                else
                {
                    startA = lineA;
                    startB = lineB;
                    while (lineA < diffDataA.Length && (lineB >= diffDataB.Length || diffDataA.modified[lineA]))
                    {
                        lineA++;
                    }
                    while (lineB < diffDataB.Length && (lineA >= diffDataA.Length || diffDataB.modified[lineB]))
                    {
                        lineB++;
                    }
                    if ((startA < lineA) || (startB < lineB))
                    {
                        item           = new DiffItem();
                        item.StartA    = startA;
                        item.StartB    = startB;
                        item.DeletedA  = lineA - startA;
                        item.InsertedB = lineB - startB;
                        list.Add(item);
                    }
                }
            }
            return(list.ToArray());
        }
        public async Task <IHttpActionResult> GetDiffData(int id)
        {
            DiffData diffData = await _repository.GetById(id);

            if (diffData == null)
            {
                return(NotFound());
            }

            try
            {
                Domain.DiffResult result = _diffAnalyser.Analyse(diffData.Left, diffData.Right);
                return(Ok(_mapper.Map <Models.Diff.DiffResult>(result)));
            }
            catch
            {
                // Some additional log routines could be added.
                // No further information is being send to the cliente due to a possible security reasons.
                return(InternalServerError());
            }
        }
Beispiel #16
0
        }// DiffText

        /// <summary>
        /// Find the difference in 2 text documents, comparing by textlines.
        /// The algorithm itself is comparing 2 arrays of numbers so when comparing 2 text documents
        /// each line is converted into a (hash) number. This hash-value is computed by storing all
        /// textlines into a common hashtable so i can find dublicates in there, and generating a
        /// new number each time a new textline is inserted.
        /// </summary>
        /// <param name="TextA">A-version of the text (usualy the old one)</param>
        /// <param name="TextB">B-version of the text (usualy the new one)</param>
        /// <param name="trimSpace">When set to true, all leading and trailing whitespace characters are stripped out before the comparation is done.</param>
        /// <param name="ignoreSpace">When set to true, all whitespace characters are converted to a single space character before the comparation is done.</param>
        /// <param name="ignoreCase">When set to true, all characters are converted to their lowercase equivivalence before the comparation is done.</param>
        /// <returns>Returns a array of Items that describe the differences.</returns>
        public static IList <DiffItem> DiffText(IList <string> textA, IList <string> textB, bool trimSpace, bool ignoreSpace, bool ignoreCase)
        {
            // prepare the input-text and convert to comparable numbers.
            var h = new Dictionary <string, int>(textA.Count + textB.Count);

            // The A-Version of the data (original data) to be compared.
            var dataA = new DiffData(DiffCodes(textA, h, trimSpace, ignoreSpace, ignoreCase));

            // The B-Version of the data (modified data) to be compared.
            var dataB = new DiffData(DiffCodes(textB, h, trimSpace, ignoreSpace, ignoreCase));

            h = null; // free up hashtable memory (maybe)

            int max = dataA.Length + dataB.Length + 1;

            int[] downVector = new int[2 * max + 2];
            int[] upVector   = new int[2 * max + 2];

            Lcs(dataA, 0, dataA.Length, dataB, 0, dataB.Length, downVector, upVector);
            return(CreateDiffs(dataA, dataB));
        }// DiffText
Beispiel #17
0
        // Function for putting a data into a database. If the parameter side equals left, then we put left endpoint data
        // otherwise we put right endpoint data
        public void AddData(int id, string side, InputData data)
        {
            {
                var    diff        = diffDAL.GetDiffDataById(id);
                string decodedData = Base64String.DecodeBase64String(data.Data);

                // If there doesn't exist any diff with given id then we create a new diff in a database
                if (diff == null)
                {
                    DiffData newDiff = new DiffData();
                    newDiff.Id = id;
                    newDiff    = UpdateDiffData(side, decodedData, newDiff);
                    diffDAL.AddData(newDiff);
                }
                // Otherwise we just update data of an existing diff
                else
                {
                    diff = UpdateDiffData(side, decodedData, diff);
                    diffDAL.UpdateDiff(diff);
                }
            }
        }
        private static DiffResult DoBenchmark(IGeometryDiff differ, DiffData payload)
        {
            var patch = RunWithTimer(CreatePatch, differ, payload, null);

            var forward = RunWithTimer(ApplyPatch, differ, payload, patch.Data);

            var reverse = RunWithTimer(UndoPatch, differ, payload, patch.Data);


            return(new DiffResult()
            {
                CreateTime = patch.Time,
                ApplyTime = forward.Time,
                UndoTime = reverse.Time,
                PatchSize = patch.Data.Length,
                ForwardCorrect = Equals(forward.Data, payload.NewGeom),
                UndoCorrect = Equals(reverse.Data, payload.OldGeom),
                CreateError = patch.Error,
                ApplyError = forward.Error,
                UnddoError = reverse.Error
            });
        }
Beispiel #19
0
        /// <summary>
        /// Loads diff information from a version control provider.
        /// </summary>
        /// <param name="remote">
        /// A <see cref="System.Boolean"/>: Whether the information
        /// should be loaded from the remote server.
        /// </param>
        void LoadDiffs(bool remote)
        {
            DiffData ddata = GetDiffData(remote);

            if (ddata.diffRunning)
            {
                return;
            }

            // Diff not yet requested. Do it now.
            ddata.diffRunning = true;

            // Run the diff in a separate thread and update the tree when done
            Thread t = new Thread(
                delegate() {
                ddata.diffException = null;
                try {
                    ddata.difs = vc.PathDiff(filepath, null, remote);
                } catch (Exception ex) {
                    ddata.diffException = ex;
                } finally {
                    ddata.diffRequested = true;
                    ddata.diffRunning   = false;
                    if (null != DiffDataLoaded)
                    {
                        Gtk.Application.Invoke(delegate {
                            DiffDataLoaded(ddata);
                            DiffDataLoaded = null;
                        });
                    }
                }
            }
                );

            t.Name         = "VCS diff loader";
            t.IsBackground = true;
            t.Start();
        }
Beispiel #20
0
        void SetFileDiff(TreeIter iter, string file)
        {
            // If diff information is already loaded, just look for the
            // diff chunk of the file and fill the tree

            DiffData ddata = GetDiffData();

            if (ddata.diffRequested)
            {
                FillDiffInfo(iter, file, ddata);
                return;
            }

            filestore.SetValue(iter, ColPath, new string[] { GettextCatalog.GetString("Loading data...") });

            if (ddata.diffRunning)
            {
                return;
            }

            DiffDataLoaded += FillDifs;
            LoadDiffs();
        }
    public override void SendResultsToHeadJudger(int InDiv, int InRound, int InPool, int InTeam)
    {
        base.SendResultsToHeadJudger(InDiv, InRound, InPool, InTeam);

        RoutineScoreData SData = Global.AllData.AllDivisions[InDiv].Rounds[InRound].Pools[(int)CurPool].Teams[InTeam].Data.RoutineScores;

        CurData.Division    = (EDivision)InDiv;
        CurData.Round       = (ERound)InRound;
        CurData.Pool        = (EPool)InPool;
        CurData.Team        = InTeam;
        CurData.JudgeNameId = GetJudgeNameId();
        SData.SetDiffResults(CurData);

        if (Networking.IsConnectedToServer)
        {
            Global.NetObj.ClientSendFinishJudgingDiff(CurData.SerializeToString());
        }
        else
        {
            CachedData = new DiffData(CurData);
            Networking.bNeedSendCachedResults = true;
        }
    }
    public override void StartEditingTeam(int InTeamIndex)
    {
        if (Global.AllData == null || CurPool == EPool.None || (int)CurPool >= Global.AllData.AllDivisions[(int)CurDivision].Rounds[(int)CurRound].Pools.Count ||
            InTeamIndex < 0 || InTeamIndex >= Global.AllData.AllDivisions[(int)CurDivision].Rounds[(int)CurRound].Pools[(int)CurPool].Teams.Count)
        {
            return;
        }

        RoutineScoreData SData = Global.AllData.AllDivisions[(int)CurDivision].Rounds[(int)CurRound].Pools[(int)CurPool].Teams[InTeamIndex].Data.RoutineScores;

        if (SData != null && SData.DiffResults != null)
        {
            CurData = null;

            base.StartEditingTeam(InTeamIndex);

            foreach (DiffData dd in SData.DiffResults)
            {
                if (dd.JudgeNameId == GetJudgeNameId())
                {
                    CurData = dd;
                    break;
                }
            }

            if (CurData == null)
            {
                CurData = new DiffData(GetNumScoreBlocks(), CurDivision, CurRound, CurPool, InTeamIndex);
            }

            for (int i = 0; i < GetNumScoreBlocks(); ++i)
            {
                NSArray[i].NumberValue = CurData.DiffScores[i];
                ConsecScores[i]        = CurData.ConsecScores[i];
            }
        }
    }
Beispiel #23
0
        public GuildUpdated GetFilledModel(SocketGuild guild)
        {
            if (AfkChannelId != null)
            {
                var oldChannel = guild.GetChannel(AfkChannelId.Before ?? 0);
                var newChannel = guild.GetChannel(AfkChannelId.After ?? 0);

                AfkChannel = new DiffData <IChannel>(oldChannel, newChannel);
            }

            if (OwnerId != null)
            {
                var oldOwner = guild.GetUserFromGuildAsync(OwnerId.Before);
                var newOwner = guild.GetUserFromGuildAsync(OwnerId.After);

                Owner = new DiffData <IUser>(oldOwner.Result, newOwner.Result);
            }

            if (SystemChannelId != null)
            {
                var oldSystemChannel = guild.GetChannel(SystemChannelId.Before ?? 0);
                var newSystemChannel = guild.GetChannel(SystemChannelId.After ?? 0);

                SystemChannel = new DiffData <IChannel>(oldSystemChannel, newSystemChannel);
            }

            if (EmbedChannelId != null)
            {
                var oldEmbedChannel = guild.GetChannel(EmbedChannelId.Before ?? 0);
                var newEmbedChannel = guild.GetChannel(EmbedChannelId.After ?? 0);

                EmbedChannel = new DiffData <IChannel>(oldEmbedChannel, newEmbedChannel);
            }

            return(this);
        }
Beispiel #24
0
    } // DiffText


    /// <summary>
    /// Find the difference in 2 text documents, comparing by textlines.
    /// The algorithm itself is comparing 2 arrays of numbers so when comparing 2 text documents
    /// each line is converted into a (hash) number. This hash-value is computed by storing all
    /// textlines into a common hashtable so i can find dublicates in there, and generating a 
    /// new number each time a new textline is inserted.
    /// </summary>
    /// <param name="TextA">A-version of the text (usualy the old one)</param>
    /// <param name="TextB">B-version of the text (usualy the new one)</param>
    /// <param name="trimSpace">When set to true, all leading and trailing whitespace characters are stripped out before the comparation is done.</param>
    /// <param name="ignoreSpace">When set to true, all whitespace characters are converted to a single space character before the comparation is done.</param>
    /// <param name="ignoreCase">When set to true, all characters are converted to their lowercase equivivalence before the comparation is done.</param>
    /// <returns>Returns a array of Items that describe the differences.</returns>
    public static Item[] DiffText(string TextA, string TextB, bool trimSpace, bool ignoreSpace, bool ignoreCase) {
      // prepare the input-text and convert to comparable numbers.
      Hashtable h = new Hashtable(TextA.Length + TextB.Length);

      // The A-Version of the data (original data) to be compared.
      DiffData DataA = new DiffData(DiffCodes(TextA, h, trimSpace, ignoreSpace, ignoreCase));

      // The B-Version of the data (modified data) to be compared.
      DiffData DataB = new DiffData(DiffCodes(TextB, h, trimSpace, ignoreSpace, ignoreCase));

      h = null; // free up hashtable memory (maybe)

      int MAX = DataA.Length + DataB.Length + 1;
      /// vector for the (0,0) to (x,y) search
      int[] DownVector = new int[2 * MAX + 2];
      /// vector for the (u,v) to (N,M) search
      int[] UpVector = new int[2 * MAX + 2];

      LCS(DataA, 0, DataA.Length, DataB, 0, DataB.Length, DownVector, UpVector);

      Optimize(DataA);
      Optimize(DataB);
      return CreateDiffs(DataA, DataB);
    } // DiffText
 void WriteDiffXml(XmlWriter writer, List <TeamDataDisplay> TeamList, int JudgeIndex)
 {
     if (TeamList.Count > 0 && TeamList[0].Data.RoutineScores.DiffResults.Count > JudgeIndex)
     {
         writer.WriteStartElement("ns2:Diff" + (JudgeIndex + 1));
         for (int TeamIndex = 0; TeamIndex < TeamList.Count; ++TeamIndex)
         {
             TeamDataDisplay tdd = TeamList[TeamIndex];
             if (JudgeIndex < tdd.Data.RoutineScores.DiffResults.Count)
             {
                 DiffData dd             = tdd.Data.RoutineScores.DiffResults[JudgeIndex];
                 int      DiffScoreCount = (int)(Global.AllData.AllDivisions[CurDivIndex].Rounds[CurRoundIndex].RoutineLengthMinutes * 4f);
                 for (int ScoreIndex = 0; ScoreIndex < DiffScoreCount; ++ScoreIndex)
                 {
                     float DiffScore = dd.DiffScores[ScoreIndex];
                     writer.WriteElementString("ns2:Team" + (TeamIndex + 1) + "Diff" + (ScoreIndex + 1), DiffScore.ToString());
                     string ConsecValue = dd.ConsecScores[ScoreIndex] == 1 ? "+" : "";
                     writer.WriteElementString("ns2:Team" + (TeamIndex + 1) + "Consec" + (ScoreIndex + 1), ConsecValue);
                 }
             }
         }
         writer.WriteEndElement();
     }
 }
Beispiel #26
0
        /// <summary>
        /// This is the algorithm to find the Shortest Middle Snake (SMS).
        /// </summary>
        /// <param name="dataLeft">sequence A</param>
        /// <param name="lowerLeft">lower bound of the actual range in DataA</param>
        /// <param name="upperLeft">upper bound of the actual range in DataA (exclusive)</param>
        /// <param name="dataRight">sequence B</param>
        /// <param name="lowerRight">lower bound of the actual range in DataB</param>
        /// <param name="upperRight">upper bound of the actual range in DataB (exclusive)</param>
        /// <returns>a MiddleSnakeData record containing x,y and u,v</returns>
        private static SMSRD SMS(DiffData dataLeft, int lowerLeft, int upperLeft, DiffData dataRight, int lowerRight, int upperRight)
        {
            SMSRD ret;
            var   max = dataLeft.Length + dataRight.Length + 1;

            var downK = lowerLeft - lowerRight; // the k-line to start the forward search
            var upK   = upperLeft - upperRight; // the k-line to start the reverse search

            var delta    = (upperLeft - lowerLeft) - (upperRight - lowerRight);
            var oddDelta = (delta & 1) != 0;

            /// vector for the (0,0) to (x,y) search
            var downVector = new int[2 * max + 2];

            /// vector for the (u,v) to (N,M) search
            var upVector = new int[2 * max + 2];

            // The vectors in the publication accepts negative indexes. the vectors implemented here are 0-based
            // and are access using a specific offset: UpOffset UpVector and DownOffset for DownVektor
            var downOffset = max - downK;
            var upOffset   = max - upK;

            var MaxD = ((upperLeft - lowerLeft + upperRight - lowerRight) / 2) + 1;

            // init vectors
            downVector[downOffset + downK + 1] = lowerLeft;
            upVector[upOffset + upK - 1]       = upperLeft;

            for (var d = 0; d <= MaxD; d++)
            {
                // Extend the forward path.
                for (var k = downK - d; k <= downK + d; k += 2)
                {
                    // find the only or better starting point
                    int x, y;
                    if (k == downK - d)
                    {
                        x = downVector[downOffset + k + 1]; // down
                    }
                    else
                    {
                        x = downVector[downOffset + k - 1] + 1; // a step to the right
                        if ((k < downK + d) && (downVector[downOffset + k + 1] >= x))
                        {
                            x = downVector[downOffset + k + 1]; // down
                        }
                    }
                    y = x - k;

                    // find the end of the furthest reaching forward D-path in diagonal k.
                    while ((x < upperLeft) && (y < upperRight) && (dataLeft.Data[x] == dataRight.Data[y]))
                    {
                        x++;
                        y++;
                    }
                    downVector[downOffset + k] = x;

                    // overlap ?
                    if (oddDelta && (upK - d < k) && (k < upK + d))
                    {
                        if (upVector[upOffset + k] <= downVector[downOffset + k])
                        {
                            ret._x = downVector[downOffset + k];
                            ret._y = downVector[downOffset + k] - k;
                            return(ret);
                        }
                    }
                }

                // Extend the reverse path.
                for (var k = upK - d; k <= upK + d; k += 2)
                {
                    // find the only or better starting point
                    int x, y;
                    if (k == upK + d)
                    {
                        x = upVector[upOffset + k - 1]; // up
                    }
                    else
                    {
                        x = upVector[upOffset + k + 1] - 1; // left
                        if ((k > upK - d) && (upVector[upOffset + k - 1] < x))
                        {
                            x = upVector[upOffset + k - 1]; // up
                        }
                    } // if
                    y = x - k;

                    while ((x > lowerLeft) && (y > lowerRight) && (dataLeft.Data[x - 1] == dataRight.Data[y - 1]))
                    {
                        x--;
                        y--; // diagonal
                    }
                    upVector[upOffset + k] = x;

                    // overlap ?
                    if (!oddDelta && (downK - d <= k) && (k <= downK + d))
                    {
                        if (upVector[upOffset + k] <= downVector[downOffset + k])
                        {
                            ret._x = downVector[downOffset + k];
                            ret._y = downVector[downOffset + k] - k;
                            return(ret);
                        }
                    }
                }
            }

            throw new InvalidOperationException("Unknown error occurred.");
        }
Beispiel #27
0
        /// <summary>
        /// Find the difference in 2 arrays of integers.
        /// </summary>
        /// <param name="ArrayA">A-version of the numbers (usualy the old one)</param>
        /// <param name="ArrayB">B-version of the numbers (usualy the new one)</param>
        /// <returns>Returns a array of Items that describe the differences.</returns>
        private static Difference[] DiffInt(int[] ArrayA, int[] ArrayB)
        {
            // The A-Version of the data (original data) to be compared.
            DiffData DataA = new DiffData(ArrayA);

            // The B-Version of the data (modified data) to be compared.
            DiffData DataB = new DiffData(ArrayB);

            LCS(DataA, 0, DataA.Length, DataB, 0, DataB.Length);
            return CreateDiffs(DataA, DataB);
        }
Beispiel #28
0
		void FillDifs (DiffData ddata)
		{
			if (disposed)
				return;

			diffRenderer.Reset ();

			if (ddata.diffException != null) {
				MessageService.ShowException (ddata.diffException, GettextCatalog.GetString ("Could not get diff information. ") + ddata.diffException.Message);
			}
			
			TreeIter it;
			if (!filestore.GetIterFirst (out it))
				return;
				
			do {
				bool filled = (bool) filestore.GetValue (it, ColFilled);
				if (filled) {
					string fileName = (string) filestore.GetValue (it, ColFullPath);
					bool remoteDiff = (bool) filestore.GetValue (it, ColStatusRemoteDiff);
					TreeIter citer;
					filestore.IterChildren (out citer, it);
					FillDiffInfo (citer, fileName, GetDiffData (remoteDiff));
				}
			}
			while (filestore.IterNext (ref it));
		}
Beispiel #29
0
		void FillDiffInfo (TreeIter iter, string file, DiffData ddata)
		{
			if (ddata.difs != null) {
				foreach (DiffInfo di in ddata.difs) {
					if (di.FileName == file) {
						filestore.SetValue (iter, ColPath, di.Content.Split ('\n'));
						filestore.SetValue (iter, ColRenderAsText, false);
						return;
					}
				}
			}
			filestore.SetValue (iter, ColPath, new string[] { GettextCatalog.GetString ("No differences found") });
			filestore.SetValue (iter, ColRenderAsText, true);
		}
Beispiel #30
0
        /// <summary>
        /// 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.
        /// </summary>
        /// <param name="DataA">sequence A</param>
        /// <param name="LowerA">lower bound of the actual range in DataA</param>
        /// <param name="UpperA">upper bound of the actual range in DataA (exclusive)</param>
        /// <param name="DataB">sequence B</param>
        /// <param name="LowerB">lower bound of the actual range in DataB</param>
        /// <param name="UpperB">upper bound of the actual range in DataB (exclusive)</param>
        private static void LCS(DiffData DataA, int LowerA, int UpperA, DiffData DataB, int LowerB, int UpperB)
        {
            // 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);
                // Debug.Write(2, "MiddleSnakeData", String.Format("{0},{1}", smsrd.x, smsrd.y));

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

        /// <summary>
        /// This is the algorithm to find the Shortest Middle Snake (Sms).
        /// </summary>
        /// <param name="DataA">sequence A</param>
        /// <param name="LowerA">lower bound of the actual range in DataA</param>
        /// <param name="UpperA">upper bound of the actual range in DataA (exclusive)</param>
        /// <param name="DataB">sequence B</param>
        /// <param name="LowerB">lower bound of the actual range in DataB</param>
        /// <param name="UpperB">upper bound of the actual range in DataB (exclusive)</param>
        /// <returns>a MiddleSnakeData record containing x,y and u,v</returns>
        private static Smsrd Sms(DiffData dataA, int lowerA, int upperA, DiffData dataB, int lowerB, int upperB, int[] downVector, int[] upVector)
        {
            Smsrd ret;
            int   max = dataA.Length + dataB.Length + 1;

            int downK = lowerA - lowerB; // the k-line to start the forward search
            int upK   = upperA - upperB; // the k-line to start the reverse search

            int  delta    = (upperA - lowerA) - (upperB - lowerB);
            bool oddDelta = (delta & 1) != 0;

            /// vector for the (0,0) to (x,y) search
            Array.Clear(downVector, 0, downVector.Length);

            /// vector for the (u,v) to (N,M) search
            Array.Clear(upVector, 0, upVector.Length);

            // The vectors in the publication accepts negative indexes. the vectors implemented here are 0-based
            // and are access using a specific offset: UpOffset UpVector and DownOffset for DownVektor
            int downOffset = max - downK;
            int upOffset   = max - upK;

            int maxD = ((upperA - lowerA + upperB - lowerB) / 2) + 1;

            // Debug.Write(2, "Sms", String.Format("Search the box: A[{0}-{1}] to B[{2}-{3}]", LowerA, UpperA, LowerB, UpperB));

            // init vectors
            downVector[downOffset + downK + 1] = lowerA;
            upVector[upOffset + upK - 1]       = upperA;

            for (int D = 0; D <= maxD; D++)
            {
                // Extend the forward path.
                for (int k = downK - D; k <= downK + D; k += 2)
                {
                    // Debug.Write(0, "Sms", "extend forward path " + k.ToString());
                    // find the only or better starting point
                    int x, y;
                    if (k == downK - D)
                    {
                        x = downVector[downOffset + k + 1]; // down
                    }
                    else
                    {
                        x = downVector[downOffset + k - 1] + 1; // a step to the right
                        if ((k < downK + D) && (downVector[downOffset + k + 1] >= x))
                        {
                            x = downVector[downOffset + k + 1]; // down
                        }
                    }
                    y = x - k;

                    // find the end of the furthest reaching forward D-path in diagonal k.
                    while ((x < upperA) && (y < upperB) && (dataA.Data[x] == dataB.Data[y]))
                    {
                        x++;
                        y++;
                    }
                    downVector[downOffset + k] = x;

                    // overlap ?
                    if (oddDelta && (upK - D < k) && (k < upK + D))
                    {
                        if (upVector[upOffset + k] <= downVector[downOffset + k])
                        {
                            ret.x = downVector[downOffset + k];
                            ret.y = downVector[downOffset + k] - k;
                            // ret.u = UpVector[UpOffset + k];      // 2002.09.20: no need for 2 points
                            // ret.v = UpVector[UpOffset + k] - k;
                            return(ret);
                        } // if
                    }     // if
                }         // for k

                // Extend the reverse path.
                for (int k = upK - D; k <= upK + D; k += 2)
                {
                    // Debug.Write(0, "Sms", "extend reverse path " + k.ToString());
                    // find the only or better starting point
                    int x, y;
                    if (k == upK + D)
                    {
                        x = upVector[upOffset + k - 1]; // up
                    }
                    else
                    {
                        x = upVector[upOffset + k + 1] - 1; // left
                        if ((k > upK - D) && (upVector[upOffset + k - 1] < x))
                        {
                            x = upVector[upOffset + k - 1]; // up
                        }
                    }// if
                    y = x - k;

                    while ((x > lowerA) && (y > lowerB) && (dataA.Data[x - 1] == dataB.Data[y - 1]))
                    {
                        x--;
                        y--; // diagonal
                    }
                    upVector[upOffset + k] = x;

                    // overlap ?
                    if (!oddDelta && (downK - D <= k) && (k <= downK + D))
                    {
                        if (upVector[upOffset + k] <= downVector[downOffset + k])
                        {
                            ret.x = downVector[downOffset + k];
                            ret.y = downVector[downOffset + k] - k;
                            // ret.u = UpVector[UpOffset + k];     // 2002.09.20: no need for 2 points
                            // ret.v = UpVector[UpOffset + k] - k;
                            return(ret);
                        } // if
                    }     // if
                }         // for k
            }             // for D

            throw new NotSupportedException("the algorithm should never come here.");
        }// Sms
        private static Result <TResult> RunWithTimer <TResult>(Func <IGeometryDiff,
                                                                     DiffData, byte[], TResult> method, IGeometryDiff differ, DiffData payload, byte[] patch)
        {
            var stopwatch = new Stopwatch();

            /*Process.GetCurrentProcess().ProcessorAffinity =
             *  new IntPtr(2); // Uses the second Core or Processor for the Test
             * Process.GetCurrentProcess().PriorityClass =
             *  ProcessPriorityClass.High; // Prevents "Normal" processes // from interrupting Threads
             * Thread.CurrentThread.Priority =
             *  ThreadPriority.Highest; // Prevents "Normal" Threads from interrupting this thread
             */
            try
            {
                double time = 0;
                var    data = default(TResult);
                for (var i = 0; i < 2; i++)
                {
                    stopwatch.Reset();
                    stopwatch.Start();
                    data = method(differ, payload, patch);
                    stopwatch.Stop();

                    if (i > 0)
                    {
                        time = stopwatch.Elapsed.TotalMilliseconds;
                    }
                }

                //var mean = Mean(res);
                // var stDev = StDev(res, mean);
                //return new Result<TResult>() {Stats = new Stats() {Mean = mean, StDev = stDev}, Data = data};
                return(new Result <TResult>()
                {
                    Time = time, Data = data
                });
            }
            catch (Exception e)
            {
                return(new Result <TResult>()
                {
                    Error = e.Message
                });
            }
        }
 private static IGeometry UndoPatch(IGeometryDiff differ, DiffData payload, byte[] patch) =>
 differ.UndoPatch(payload.NewGeom, patch);
 private static IGeometry ApplyPatch(IGeometryDiff differ, DiffData payload, byte[] patch) =>
 differ.ApplyPatch(payload.OldGeom, patch);
Beispiel #35
0
		public void ClearDiff()
		{
			if (diffData == null)
				return;

			for (var line = diffData.LineMatch.Count - 1; line >= 0; --line)
				if (diffData.LineMatch[line] == LCS.MatchType.Gap)
				{
					lineOffset.RemoveAt(line);
					endingOffset.RemoveAt(line);
				}

			diffData = null;
		}
    } // Optimize


    /// <summary>
    /// Find the difference in 2 arrays of integers.
    /// </summary>
    /// <param name="ArrayA">A-version of the numbers (usualy the old one)</param>
    /// <param name="ArrayB">B-version of the numbers (usualy the new one)</param>
    /// <returns>Returns a array of Items that describe the differences.</returns>
    public static Item[] DiffInt(int[] ArrayA, int[] ArrayB) {
      // The A-Version of the data (original data) to be compared.
      DiffData DataA = new DiffData(ArrayA);

      // The B-Version of the data (modified data) to be compared.
      DiffData DataB = new DiffData(ArrayB);

      int MAX = DataA.Length + DataB.Length + 1;
      /// vector for the (0,0) to (x,y) search
      int[] DownVector = new int[2 * MAX + 2];
      /// vector for the (u,v) to (N,M) search
      int[] UpVector = new int[2 * MAX + 2];

      LCS(DataA, 0, DataA.Length, DataB, 0, DataB.Length, DownVector, UpVector);
      return CreateDiffs(DataA, DataB);
    } // Diff
    }         // DiffCodes

    /// <summary>
    /// This is the algorithm to find the Shortest Middle Snake (SMS).
    /// </summary>
    /// <param name="DataA">sequence A</param>
    /// <param name="LowerA">lower bound of the actual range in DataA</param>
    /// <param name="UpperA">upper bound of the actual range in DataA (exclusive)</param>
    /// <param name="DataB">sequence B</param>
    /// <param name="LowerB">lower bound of the actual range in DataB</param>
    /// <param name="UpperB">upper bound of the actual range in DataB (exclusive)</param>
    /// <param name="DownVector">a vector for the (0,0) to (x,y) search. Passed as a parameter for speed reasons.</param>
    /// <param name="UpVector">a vector for the (u,v) to (N,M) search. Passed as a parameter for speed reasons.</param>
    /// <returns>a MiddleSnakeData record containing x,y and u,v</returns>
    private static SMSRD SMS(DiffData DataA, int LowerA, int UpperA, DiffData DataB, int LowerB, int UpperB,
                             int[] DownVector, int[] UpVector)
    {
        SMSRD ret;
        int   MAX = DataA.Length + DataB.Length + 1;

        int DownK = LowerA - LowerB; // the k-line to start the forward search
        int UpK   = UpperA - UpperB; // the k-line to start the reverse search

        int  Delta    = (UpperA - LowerA) - (UpperB - LowerB);
        bool oddDelta = (Delta & 1) != 0;

        // The vectors in the publication accepts negative indexes. the vectors implemented here are 0-based
        // and are access using a specific offset: UpOffset UpVector and DownOffset for DownVektor
        int DownOffset = MAX - DownK;
        int UpOffset   = MAX - UpK;

        int MaxD = ((UpperA - LowerA + UpperB - LowerB) / 2) + 1;

        // Debug.Write(2, "SMS", String.Format("Search the box: A[{0}-{1}] to B[{2}-{3}]", LowerA, UpperA, LowerB, UpperB));

        // init vectors
        DownVector[DownOffset + DownK + 1] = LowerA;
        UpVector[UpOffset + UpK - 1]       = UpperA;

        for (int D = 0; D <= MaxD; D++)
        {
            // Extend the forward path.
            for (int k = DownK - D; k <= DownK + D; k += 2)
            {
                // Debug.Write(0, "SMS", "extend forward path " + k.ToString());

                // find the only or better starting point
                int x, y;
                if (k == DownK - D)
                {
                    x = DownVector[DownOffset + k + 1]; // down
                }
                else
                {
                    x = DownVector[DownOffset + k - 1] + 1; // a step to the right
                    if ((k < DownK + D) && (DownVector[DownOffset + k + 1] >= x))
                    {
                        x = DownVector[DownOffset + k + 1]; // down
                    }
                }
                y = x - k;

                // find the end of the furthest reaching forward D-path in diagonal k.
                while ((x < UpperA) && (y < UpperB) && (DataA.data[x] == DataB.data[y]))
                {
                    x++; y++;
                }
                DownVector[DownOffset + k] = x;

                // overlap ?
                if (oddDelta && (UpK - D < k) && (k < UpK + D))
                {
                    if (UpVector[UpOffset + k] <= DownVector[DownOffset + k])
                    {
                        ret.x = DownVector[DownOffset + k];
                        ret.y = DownVector[DownOffset + k] - k;
                        // ret.u = UpVector[UpOffset + k];      // 2002.09.20: no need for 2 points
                        // ret.v = UpVector[UpOffset + k] - k;
                        return(ret);
                    } // if
                }     // if
            }         // for k

            // Extend the reverse path.
            for (int k = UpK - D; k <= UpK + D; k += 2)
            {
                // Debug.Write(0, "SMS", "extend reverse path " + k.ToString());

                // find the only or better starting point
                int x, y;
                if (k == UpK + D)
                {
                    x = UpVector[UpOffset + k - 1]; // up
                }
                else
                {
                    x = UpVector[UpOffset + k + 1] - 1; // left
                    if ((k > UpK - D) && (UpVector[UpOffset + k - 1] < x))
                    {
                        x = UpVector[UpOffset + k - 1]; // up
                    }
                } // if
                y = x - k;

                while ((x > LowerA) && (y > LowerB) && (DataA.data[x - 1] == DataB.data[y - 1]))
                {
                    x--; y--; // diagonal
                }
                UpVector[UpOffset + k] = x;

                // overlap ?
                if (!oddDelta && (DownK - D <= k) && (k <= DownK + D))
                {
                    if (UpVector[UpOffset + k] <= DownVector[DownOffset + k])
                    {
                        ret.x = DownVector[DownOffset + k];
                        ret.y = DownVector[DownOffset + k] - k;
                        // ret.u = UpVector[UpOffset + k];     // 2002.09.20: no need for 2 points
                        // ret.v = UpVector[UpOffset + k] - k;
                        return(ret);
                    } // if
                }     // if
            }         // for k
        }             // for D

        throw new ApplicationException("the algorithm should never come here.");
    } // SMS
Beispiel #38
0
        /// <summary>
        /// This is the algorithm to find the Shortest Middle Snake (SMS).
        /// </summary>
        /// <param name="DataA">sequence A</param>
        /// <param name="LowerA">lower bound of the actual range in DataA</param>
        /// <param name="UpperA">upper bound of the actual range in DataA (exclusive)</param>
        /// <param name="DataB">sequence B</param>
        /// <param name="LowerB">lower bound of the actual range in DataB</param>
        /// <param name="UpperB">upper bound of the actual range in DataB (exclusive)</param>
        /// <returns>a MiddleSnakeData record containing x,y and u,v</returns>
        private static SMSRD SMS(DiffData DataA, int LowerA, int UpperA, DiffData DataB, int LowerB, int UpperB)
        {
            SMSRD ret;
            int MAX = DataA.Length + DataB.Length + 1;

            int DownK = LowerA - LowerB; // the k-line to start the forward search
            int UpK = UpperA - UpperB; // the k-line to start the reverse search

            int Delta = (UpperA - LowerA) - (UpperB - LowerB);
            bool oddDelta = (Delta & 1) != 0;

            /// vector for the (0,0) to (x,y) search
            int[] DownVector = new int[2 * MAX + 2];

            /// vector for the (u,v) to (N,M) search
            int[] UpVector = new int[2 * MAX + 2];

            // The vectors in the publication accepts negative indexes. the vectors implemented here are 0-based
            // and are access using a specific offset: UpOffset UpVector and DownOffset for DownVektor
            int DownOffset = MAX - DownK;
            int UpOffset = MAX - UpK;

            int MaxD = ((UpperA - LowerA + UpperB - LowerB) / 2) + 1;

            // Debug.Write(2, "SMS", String.Format("Search the box: A[{0}-{1}] to B[{2}-{3}]", LowerA, UpperA, LowerB, UpperB));

            // init vectors
            DownVector[DownOffset + DownK + 1] = LowerA;
            UpVector[UpOffset + UpK - 1] = UpperA;

            for (int D = 0; D <= MaxD; D++)
            {

                // Extend the forward path.
                for (int k = DownK - D; k <= DownK + D; k += 2)
                {
                    // Debug.Write(0, "SMS", "extend forward path " + k.ToString());

                    // find the only or better starting point
                    int x, y;
                    if (k == DownK - D)
                    {
                        x = DownVector[DownOffset + k + 1]; // down
                    }
                    else
                    {
                        x = DownVector[DownOffset + k - 1] + 1; // a step to the right
                        if ((k < DownK + D) && (DownVector[DownOffset + k + 1] >= x))
                            x = DownVector[DownOffset + k + 1]; // down
                    }
                    y = x - k;

                    // find the end of the furthest reaching forward D-path in diagonal k.
                    while ((x < UpperA) && (y < UpperB) && (DataA.data[x] == DataB.data[y]))
                    {
                        x++; y++;
                    }
                    DownVector[DownOffset + k] = x;

                    // overlap ?
                    if (oddDelta && (UpK - D < k) && (k < UpK + D))
                    {
                        if (UpVector[UpOffset + k] <= DownVector[DownOffset + k])
                        {
                            ret.x = DownVector[DownOffset + k];
                            ret.y = DownVector[DownOffset + k] - k;
                            // ret.u = UpVector[UpOffset + k];      // 2002.09.20: no need for 2 points
                            // ret.v = UpVector[UpOffset + k] - k;
                            return (ret);
                        } // if
                    } // if

                } // for k

                // Extend the reverse path.
                for (int k = UpK - D; k <= UpK + D; k += 2)
                {
                    // Debug.Write(0, "SMS", "extend reverse path " + k.ToString());

                    // find the only or better starting point
                    int x, y;
                    if (k == UpK + D)
                    {
                        x = UpVector[UpOffset + k - 1]; // up
                    }
                    else
                    {
                        x = UpVector[UpOffset + k + 1] - 1; // left
                        if ((k > UpK - D) && (UpVector[UpOffset + k - 1] < x))
                            x = UpVector[UpOffset + k - 1]; // up
                    } // if
                    y = x - k;

                    while ((x > LowerA) && (y > LowerB) && (DataA.data[x - 1] == DataB.data[y - 1]))
                    {
                        x--; y--; // diagonal
                    }
                    UpVector[UpOffset + k] = x;

                    // overlap ?
                    if (!oddDelta && (DownK - D <= k) && (k <= DownK + D))
                    {
                        if (UpVector[UpOffset + k] <= DownVector[DownOffset + k])
                        {
                            ret.x = DownVector[DownOffset + k];
                            ret.y = DownVector[DownOffset + k] - k;
                            // ret.u = UpVector[UpOffset + k];     // 2002.09.20: no need for 2 points
                            // ret.v = UpVector[UpOffset + k] - k;
                            return (ret);
                        } // if
                    } // if

                } // for k

            } // for D

            throw new ApplicationException("the algorithm should never come here.");
        }
Beispiel #39
0
        /// <summary>
        /// Find the difference in 2 text documents, comparing by textlines.
        /// The algorithm itself is comparing 2 arrays of numbers so when comparing 2 text documents
        /// each line is converted into a (hash) number. This hash-value is computed by storing all
        /// textlines into a common hashtable so i can find dublicates in there, and generating a 
        /// new number each time a new textline is inserted.
        /// </summary>
        /// <param name="TextA">A-version of the text (usualy the old one)</param>
        /// <param name="TextB">B-version of the text (usualy the new one)</param>
        /// <returns>Returns a array of Items that describe the differences.</returns>
        private static Difference[] FindDifferences(string TextA, string TextB)
        {
            // prepare the input-text and convert to comparable numbers.
            Hashtable h = new Hashtable(TextA.Length + TextB.Length);

            // The A-Version of the data (original data) to be compared.
            DiffData DataA = new DiffData(DiffCodes(TextA, h));

            // The B-Version of the data (modified data) to be compared.
            DiffData DataB = new DiffData(DiffCodes(TextB, h));

            h = null; // free up hashtable memory (maybe)

            LCS(DataA, 0, DataA.Length, DataB, 0, DataB.Length);
            return CreateDiffs(DataA, DataB);
        }