Mercurial > hg4j
comparison src/org/tmatesoft/hg/internal/ArrayHelper.java @ 310:237de162be28
Fix building sort reverse array when element was initially in correct position.
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Sat, 24 Sep 2011 13:25:33 +0200 |
parents | 2f2ab5c27f41 |
children | b9592e21176a |
comparison
equal
deleted
inserted
replaced
309:962f78aac342 | 310:237de162be28 |
---|---|
27 @SuppressWarnings("unchecked") | 27 @SuppressWarnings("unchecked") |
28 public void sort(Comparable<?>[] a) { | 28 public void sort(Comparable<?>[] a) { |
29 // Object[] aux = (Object[]) a.clone(); | 29 // Object[] aux = (Object[]) a.clone(); |
30 reverse = new int[a.length]; | 30 reverse = new int[a.length]; |
31 sort1((Comparable<Object>[])a, 0, a.length); | 31 sort1((Comparable<Object>[])a, 0, a.length); |
32 for (int i = 0; i < reverse.length; i++) { | |
33 // element that was not moved don't have an index in reverse. | |
34 // perhaps, can do it inside sort alg? | |
35 // TODO tests! | |
36 if (reverse[i] == 0) { | |
37 reverse[i] = i+1; | |
38 } | |
39 } | |
32 } | 40 } |
33 | 41 |
34 private void sort1(Comparable<Object> x[], int off, int len) { | 42 private void sort1(Comparable<Object> x[], int off, int len) { |
35 // Insertion sort on smallest arrays | 43 // Insertion sort on smallest arrays |
36 if (len < 7) { | 44 if (len < 7) { |