Changeset 6224 in josm for trunk/src/org
- Timestamp:
- 2013-09-08T06:23:57+02:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Diff.java
r6142 r6224 8 8 /* 9 9 * $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 * 10 29 * Revision 1.7 2009/01/19 03:05:26 stuart 11 30 * Fix StackOverflow bug with heuristic on reported by Jimmy Han. … … 28 47 */ 29 48 30 import java.util.Hashtable; 49 import java.util.HashMap; 50 import java.util.Map; 31 51 32 52 /** A class to compare vectors of objects. The result of comparison … … 76 96 */ 77 97 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) }; 81 100 } 82 101 … … 104 123 search of the edit matrix. */ 105 124 private int fdiagoff, bdiagoff; 106 private final file_data[] filevec = new file_data[2];125 private final file_data[] filevec; 107 126 private int cost; 108 127 /** Snakes bigger than this are considered "big". */ … … 350 369 if (c == 1) 351 370 /* 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. */ 355 374 throw new IllegalArgumentException("Empty subsequence"); 356 375 else … … 558 577 /** Line number of 1st inserted line. */ 559 578 public final int line1; 579 /** Change is ignorable. */ 580 public boolean ignore; 560 581 561 582 /** Cons an additional entry onto the front of an edit script OLD. … … 572 593 this.deleted = deleted; 573 594 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; 575 600 } 576 601 } … … 687 712 688 713 /* Find end of this run of discardable lines. 689 Count how many are provisionally discardable. */714 Count how many are provisionally discardable. */ 690 715 for (j = i; j < end; j++) 691 716 { … … 723 748 724 749 /* MINIMUM is approximate square root of LENGTH/4. 725 A subrun of two or more provisionals can stand726 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. */ 728 753 while ((tem = tem >> 2) > 0) { 729 754 minimum *= 2; … … 732 757 733 758 /* Cancel any subrun of MINIMUM or more provisionals 734 within the larger run. */759 within the larger run. */ 735 760 for (j = 0, consec = 0; j < length; j++) 736 761 if (discards[i + j] != 2) { … … 744 769 745 770 /* Scan from beginning of run 746 until we find 3 or more nonprovisionals in a row747 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. */ 749 774 for (j = 0, consec = 0; j < length; j++) 750 775 { … … 808 833 } 809 834 810 file_data( Object[] data,Hashtable<Object, Integer> h) {835 file_data(int[] data) { 811 836 buffered_lines = data.length; 812 813 equivs = new int[buffered_lines]; 837 equivs = data; 814 838 undiscarded = new int[buffered_lines]; 815 839 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 817 845 for (int i = 0; i < data.length; ++i) { 818 846 Integer ir = h.get(data[i]); 819 847 if (ir == null) { 820 h.put(data[i], new Integer(equivs[i] = equiv_max++));848 h.put(data[i],equivs[i] = equiv_max++); 821 849 } else { 822 850 equivs[i] = ir.intValue(); … … 852 880 853 881 /* 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. */ 855 883 856 884 while (i < i_end && !changed[1+i]) … … 858 886 while (other_changed[1+j++]) { 859 887 /* 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. */ 861 889 other_preceding = j; 862 890 } … … 917 945 final int buffered_lines; 918 946 947 /** Number of common prefix elements. */ 948 final int prefix_lines = 0; 949 919 950 /** Vector, indexed by line number, containing an equivalence code for 920 each line. It is this vector that is actually compared with that921 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. */ 922 953 private final int[] equivs; 923 954 924 955 /** 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. */ 926 957 final int[] undiscarded; 927 958 928 959 /** 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. */ 930 961 final int[] realindexes; 931 962 … … 934 965 935 966 /** 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. */ 938 969 boolean[] changed_flag; 939 970
Note:
See TracChangeset
for help on using the changeset viewer.