Ejemplo n.º 1
0
        public ArrayList DiffResult()
        {
            ArrayList retval = new ArrayList();
            int       dcount = destList.Count();
            int       scount = sourceList.Count();

            //Deal with the special case of empty files
            if (dcount == 0)
            {
                if (scount > 0)
                {
                    retval.Add(CompareResultSpan.CreateDeleteSource(0, scount));
                }
                return(retval);
            }

            if (scount == 0)
            {
                retval.Add(CompareResultSpan.CreateAddDestination(0, dcount));
                return(retval);
            }

            matchList.Sort();
            int curDest            = 0;
            int curSource          = 0;
            CompareResultSpan last = null;

            //Process each match record
            foreach (CompareResultSpan drs in matchList)
            {
                if ((!AddChanges(retval, curDest, drs.DestinationIndex, curSource, drs.SourceIndex)) &&
                    (last != null))
                {
                    last.AddLength(drs.Length);
                }
                else
                {
                    retval.Add(drs);
                }
                curDest   = drs.DestinationIndex + drs.Length;
                curSource = drs.SourceIndex + drs.Length;
                last      = drs;
            }

            //Process any tail end data
            AddChanges(retval, curDest, dcount, curSource, scount);

            return(retval);
        }
Ejemplo n.º 2
0
        private static bool AddChanges(

            IList report,
            int curDest,
            int nextDest,
            int curSource,
            int nextSource)
        {
            bool retval     = false;
            int  diffDest   = nextDest - curDest;
            int  diffSource = nextSource - curSource;

            if (diffDest > 0)
            {
                if (diffSource > 0)
                {
                    int minDiff = Math.Min(diffDest, diffSource);
                    report.Add(CompareResultSpan.CreateReplace(curDest, curSource, minDiff));
                    if (diffDest > diffSource)
                    {
                        curDest += minDiff;
                        report.Add(CompareResultSpan.CreateAddDestination(curDest, diffDest - diffSource));
                    }
                    else
                    {
                        if (diffSource > diffDest)
                        {
                            curSource += minDiff;
                            report.Add(CompareResultSpan.CreateDeleteSource(curSource, diffSource - diffDest));
                        }
                    }
                }
                else
                {
                    report.Add(CompareResultSpan.CreateAddDestination(curDest, diffDest));
                }
                retval = true;
            }
            else
            {
                if (diffSource > 0)
                {
                    report.Add(CompareResultSpan.CreateDeleteSource(curSource, diffSource));
                    retval = true;
                }
            }
            return(retval);
        }