Ignore:
Timestamp:
2013-09-08T06:23:57+02:00 (11 years ago)
Author:
Don-vip
Message:

update to Diff v1.15 (2013/04/01) from http://www.bmsi.com/java/#diff

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/Diff.java

    r6142 r6224  
    88/*
    99 * $Log: Diff.java,v $
     10 * Revision 1.15  2013/04/01 16:27:31  stuart
     11 * Fix DiffPrint unified format with test cases.
     12 * Begin porting some diff-2.7 features.
     13 *
     14 * Revision 1.14  2010/03/03 21:21:25  stuart
     15 * Test new direct equivalence API
     16 *
     17 * Revision 1.13  2009/12/07 17:43:17  stuart
     18 * Compute equiv_max for int[] ctor
     19 *
     20 * Revision 1.12  2009/12/07 17:34:46  stuart
     21 * Ctor with int[].
     22 *
     23 * Revision 1.11  2009/11/15 01:11:54  stuart
     24 * Diff doesn't need to be generic
     25 *
     26 * Revision 1.10  2009/11/15 00:54:03  stuart
     27 * Update to Java 5 containers
     28 *
    1029 * Revision 1.7  2009/01/19 03:05:26  stuart
    1130 * Fix StackOverflow bug with heuristic on reported by Jimmy Han.
     
    2847 */
    2948
    30 import java.util.Hashtable;
     49import java.util.HashMap;
     50import java.util.Map;
    3151
    3252/** A class to compare vectors of objects.  The result of comparison
     
    7696     */
    7797    public Diff(Object[] a,Object[] b) {
    78         Hashtable<Object, Integer> h = new Hashtable<Object, Integer>(a.length + b.length);
    79         filevec[0] = new file_data(a,h);
    80         filevec[1] = new file_data(b,h);
     98        Map<Object,Integer> h = new HashMap<Object,Integer>(a.length + b.length);
     99        filevec = new file_data[] { new file_data(a,h),new file_data(b,h) };
    81100    }
    82101
     
    104123                   search of the edit matrix. */
    105124    private int fdiagoff, bdiagoff;
    106     private final file_data[] filevec = new file_data[2];
     125    private final file_data[] filevec;
    107126    private int cost;
    108127    /** Snakes bigger than this are considered "big". */
     
    350369            if (c == 1)
    351370                /* This should be impossible, because it implies that
    352            one of the two subsequences is empty,
    353            and that case was handled above without calling `diag'.
    354            Let's verify that this is true.  */
     371                   one of the two subsequences is empty,
     372                   and that case was handled above without calling `diag'.
     373                   Let's verify that this is true.  */
    355374                throw new IllegalArgumentException("Empty subsequence");
    356375            else
     
    558577        /** Line number of 1st inserted line.  */
    559578        public final int line1;
     579        /** Change is ignorable. */
     580        public boolean ignore;
    560581
    561582        /** Cons an additional entry onto the front of an edit script OLD.
     
    572593            this.deleted = deleted;
    573594            this.link = old;
    574             //System.err.println(line0+","+line1+","+inserted+","+deleted);
     595        }
     596
     597        public String toString() {
     598            String s = String.format("%d -%d +%d %d",line0,deleted,inserted,line1);
     599            return (link != null) ? s = s + '\n' + link : s;
    575600        }
    576601    }
     
    687712
    688713                    /* Find end of this run of discardable lines.
    689            Count how many are provisionally discardable.  */
     714                       Count how many are provisionally discardable.  */
    690715                    for (j = i; j < end; j++)
    691716                    {
     
    723748
    724749                        /* MINIMUM is approximate square root of LENGTH/4.
    725                A subrun of two or more provisionals can stand
    726                when LENGTH is at least 16.
    727                A subrun of 4 or more can stand when LENGTH >= 64.  */
     750                           A subrun of two or more provisionals can stand
     751                           when LENGTH is at least 16.
     752                           A subrun of 4 or more can stand when LENGTH >= 64.  */
    728753                        while ((tem = tem >> 2) > 0) {
    729754                            minimum *= 2;
     
    732757
    733758                        /* Cancel any subrun of MINIMUM or more provisionals
    734                within the larger run.  */
     759                           within the larger run.  */
    735760                        for (j = 0, consec = 0; j < length; j++)
    736761                            if (discards[i + j] != 2) {
     
    744769
    745770                        /* Scan from beginning of run
    746                until we find 3 or more nonprovisionals in a row
    747                or until the first nonprovisional at least 8 lines in.
    748                Until that point, cancel any provisionals.  */
     771                           until we find 3 or more nonprovisionals in a row
     772                           or until the first nonprovisional at least 8 lines in.
     773                           Until that point, cancel any provisionals.  */
    749774                        for (j = 0, consec = 0; j < length; j++)
    750775                        {
     
    808833        }
    809834
    810         file_data(Object[] data,Hashtable<Object, Integer> h) {
     835        file_data(int[] data) {
    811836            buffered_lines = data.length;
    812 
    813             equivs = new int[buffered_lines];
     837            equivs = data;
    814838            undiscarded = new int[buffered_lines];
    815839            realindexes = new int[buffered_lines];
    816 
     840        }
     841       
     842        file_data(Object[] data,Map<Object,Integer> h) {
     843            this(new int[data.length]);
     844            // FIXME: diff 2.7 removes common prefix and common suffix
    817845            for (int i = 0; i < data.length; ++i) {
    818846                Integer ir = h.get(data[i]);
    819847                if (ir == null) {
    820                     h.put(data[i],new Integer(equivs[i] = equiv_max++));
     848                    h.put(data[i],equivs[i] = equiv_max++);
    821849                } else {
    822850                    equivs[i] = ir.intValue();
     
    852880
    853881                /* Scan forwards to find beginning of another run of changes.
    854          Also keep track of the corresponding point in the other file.  */
     882                   Also keep track of the corresponding point in the other file.  */
    855883
    856884                while (i < i_end && !changed[1+i])
     
    858886                    while (other_changed[1+j++]) {
    859887                        /* Non-corresponding lines in the other file
    860                will count as the preceding batch of changes.  */
     888                           will count as the preceding batch of changes.  */
    861889                        other_preceding = j;
    862890                    }
     
    917945        final int buffered_lines;
    918946
     947        /** Number of common prefix elements. */
     948        final int prefix_lines = 0;
     949
    919950        /** Vector, indexed by line number, containing an equivalence code for
    920        each line.  It is this vector that is actually compared with that
    921        of another file to generate differences. */
     951           each line.  It is this vector that is actually compared with that
     952           of another file to generate differences. */
    922953        private final int[]     equivs;
    923954
    924955        /** Vector, like the previous one except that
    925        the elements for discarded lines have been squeezed out.  */
     956           the elements for discarded lines have been squeezed out.  */
    926957        final int[]    undiscarded;
    927958
    928959        /** Vector mapping virtual line numbers (not counting discarded lines)
    929        to real ones (counting those lines).  Both are origin-0.  */
     960           to real ones (counting those lines).  Both are origin-0.  */
    930961        final int[]    realindexes;
    931962
     
    934965
    935966        /** Array, indexed by real origin-1 line number,
    936        containing true for a line that is an insertion or a deletion.
    937        The results of comparison are stored here.  */
     967           containing true for a line that is an insertion or a deletion.
     968           The results of comparison are stored here.  */
    938969        boolean[]       changed_flag;
    939970
Note: See TracChangeset for help on using the changeset viewer.