Ejemplo n.º 1
0
        /// <summary>
        /// Returns forward D path
        /// </summary>
        /// <param name="subArrayA">Sub-sequence A</param>
        /// <param name="subArrayB">Sub-sequence B</param>
        /// <param name="d">D index</param>
        /// <param name="k">K index</param>
        /// <returns>X coordinate</returns>
        private int GetForwardDPaths(SubArray <T> subArrayA, SubArray <T> subArrayB, int d, int k)
        {
            DiagonalVector vector = _vectorForward;

            int x;

            if (k == -d || k != d && vector[k - 1] < vector[k + 1])
            {
                x = vector[k + 1];
            }
            else
            {
                x = vector[k - 1] + 1;
            }

            int y = x - k;

            while (x < subArrayA.Length && y < subArrayB.Length && subArrayA[x + 1].CompareTo(subArrayB[y + 1]) == 0)
            {
                x++;
                y++;
            }

            vector[k] = x;

            return(x);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns reverse D path
        /// </summary>
        /// <param name="subArrayA">Sub-sequence A</param>
        /// <param name="subArrayB">Sub-sequence B</param>
        /// <param name="d">D index</param>
        /// <param name="k">K index</param>
        /// <param name="delta">Delta</param>
        /// <returns>X coordinate</returns>
        private int GetReverseDPaths(SubArray <T> subArrayA, SubArray <T> subArrayB, int d, int k, int delta)
        {
            DiagonalVector vector = _vectorReverse;

            int p = k + delta;

            int x;

            if (k == -d || k != d && vector[p + 1] <= vector[p - 1])
            {
                x = vector[p + 1] - 1;
            }
            else
            {
                x = vector[p - 1];
            }

            int y = x - p;

            while (x > 0 && y > 0 && subArrayA[x].CompareTo(subArrayB[y]) == 0)
            {
                x--;
                y--;
            }

            vector[p] = x;

            return(x);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="listA">Left sequence</param>
        /// <param name="listB">Right sequence</param>
        /// <param name="supportChangeEditType">If "Change" EditType is allowed (default is delete and insert only)</param>
        public MyersDiff(IList <T> listA, IList <T> listB, bool supportChangeEditType)
        {
            _listA = listA;
            _listB = listB;
            _supportChangeEditType = supportChangeEditType;

            int n = listA.Count;
            int m = listB.Count;

            _vectorForward = new DiagonalVector(n, m);
            _vectorReverse = new DiagonalVector(n, m);
        }