diff 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
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/ArrayHelper.java	Sat Sep 24 13:02:48 2011 +0200
+++ b/src/org/tmatesoft/hg/internal/ArrayHelper.java	Sat Sep 24 13:25:33 2011 +0200
@@ -29,6 +29,14 @@
 //		Object[] aux = (Object[]) a.clone();
 		reverse = new int[a.length];
 		sort1((Comparable<Object>[])a, 0, a.length);
+		for (int i = 0; i < reverse.length; i++) {
+			// element that was not moved don't have an index in reverse.
+			// perhaps, can do it inside sort alg?
+			// TODO tests!
+			if (reverse[i] == 0) {
+				reverse[i] = i+1;
+			}
+		}
 	}
 	
     private void sort1(Comparable<Object> x[], int off, int len) {