1 Clazz.declarePackage ("jalview.util");
2 Clazz.load (null, "jalview.util.QuickSort", ["java.lang.Float", "java.util.Arrays"], function () {
3 c$ = Clazz.declareType (jalview.util, "QuickSort");
4 c$.sortInt = Clazz.defineMethod (c$, "sortInt",
6 jalview.util.QuickSort.sortInt (arr, 0, arr.length - 1, s);
8 c$.sortFloatObject = Clazz.defineMethod (c$, "sortFloatObject",
10 jalview.util.QuickSort.sortFloat (arr, 0, arr.length - 1, s);
12 c$.sortDouble = Clazz.defineMethod (c$, "sortDouble",
14 jalview.util.QuickSort.sortDouble (arr, 0, arr.length - 1, s);
16 c$.sort = Clazz.defineMethod (c$, "sort",
18 jalview.util.QuickSort.stringSort (arr, 0, arr.length - 1, s);
20 c$.stringSort = Clazz.defineMethod (c$, "stringSort",
21 function (arr, p, r, s) {
24 q = jalview.util.QuickSort.stringPartition (arr, p, r, s);
25 jalview.util.QuickSort.stringSort (arr, p, q, s);
26 jalview.util.QuickSort.stringSort (arr, q + 1, r, s);
28 c$.sortFloat = Clazz.defineMethod (c$, "sortFloat",
29 function (arr, p, r, s) {
32 q = jalview.util.QuickSort.partitionFloat (arr, p, r, s);
33 jalview.util.QuickSort.sortFloat (arr, p, q, s);
34 jalview.util.QuickSort.sortFloat (arr, q + 1, r, s);
36 c$.sortInt = Clazz.defineMethod (c$, "sortInt",
37 function (arr, p, r, s) {
40 q = jalview.util.QuickSort.partitionInt (arr, p, r, s);
41 jalview.util.QuickSort.sortInt (arr, p, q, s);
42 jalview.util.QuickSort.sortInt (arr, q + 1, r, s);
44 c$.partitionFloat = Clazz.defineMethod (c$, "partitionFloat",
45 function (arr, p, r, s) {
67 c$.partitionInt = Clazz.defineMethod (c$, "partitionInt",
68 function (arr, p, r, s) {
90 c$.stringPartition = Clazz.defineMethod (c$, "stringPartition",
91 function (arr, p, r, s) {
98 } while (arr[j].compareTo (x) < 0);
101 } while (arr[i].compareTo (x) > 0);
113 c$.sortFloatChar = Clazz.defineMethod (c$, "sortFloatChar",
115 var f1 = Clazz.newFloatArray (arr.length, 0);
116 var s1 = Clazz.newCharArray (s.length, '\0');
117 var nextZeroValue = 0;
118 var nextNonZeroValue = arr.length - 1;
119 for (var i = 0; i < arr.length; i++) {
122 f1[nextNonZeroValue] = val;
123 s1[nextNonZeroValue] = s[i];
126 f1[nextZeroValue] = val;
127 s1[nextZeroValue] = s[i];
130 System.arraycopy (f1, 0, arr, 0, nextZeroValue);
131 System.arraycopy (s1, 0, s, 0, nextZeroValue);
132 if (nextZeroValue == arr.length) {
134 }var nonZeroFloats = java.util.Arrays.copyOfRange (f1, nextZeroValue, f1.length);
135 var nonZeroChars = java.util.Arrays.copyOfRange (s1, nextZeroValue, s1.length);
136 jalview.util.QuickSort.externalSortFloat (nonZeroFloats, nonZeroChars);
137 System.arraycopy (nonZeroFloats, 0, arr, nextZeroValue, nonZeroFloats.length);
138 System.arraycopy (nonZeroChars, 0, s, nextZeroValue, nonZeroChars.length);
140 c$.externalSortFloat = Clazz.defineMethod (c$, "externalSortFloat",
142 var length = arr.length;
143 var indices = jalview.util.QuickSort.makeIndexArray (length);
144 java.util.Arrays.sort (indices, new jalview.util.QuickSort.FloatComparator (arr));
145 var sortedFloats = Clazz.newFloatArray (length, 0);
146 var sortedChars = Clazz.newCharArray (s.length, '\0');
147 for (var i = 0; i < length; i++) {
148 sortedFloats[i] = arr[indices[i]];
149 sortedChars[i] = s[indices[i]];
151 System.arraycopy (sortedFloats, 0, arr, 0, length);
152 System.arraycopy (sortedChars, 0, s, 0, s.length);
154 c$.makeIndexArray = Clazz.defineMethod (c$, "makeIndexArray",
156 var indices = new Array (length);
157 for (var i = 0; i < length; i++) {
158 indices[i] = new Integer (i);
162 c$.sortIntChar = Clazz.defineMethod (c$, "sortIntChar",
164 var f1 = Clazz.newIntArray (arr.length, 0);
165 var s1 = Clazz.newCharArray (s.length, '\0');
166 var nextZeroValue = 0;
167 var nextNonZeroValue = arr.length - 1;
168 for (var i = 0; i < arr.length; i++) {
171 f1[nextNonZeroValue] = val;
172 s1[nextNonZeroValue] = s[i];
175 f1[nextZeroValue] = val;
176 s1[nextZeroValue] = s[i];
179 System.arraycopy (f1, 0, arr, 0, nextZeroValue);
180 System.arraycopy (s1, 0, s, 0, nextZeroValue);
181 if (nextZeroValue == arr.length) {
183 }var nonZeroInts = java.util.Arrays.copyOfRange (f1, nextZeroValue, f1.length);
184 var nonZeroChars = java.util.Arrays.copyOfRange (s1, nextZeroValue, s1.length);
185 jalview.util.QuickSort.externalSortInt (nonZeroInts, nonZeroChars);
186 System.arraycopy (nonZeroInts, 0, arr, nextZeroValue, nonZeroInts.length);
187 System.arraycopy (nonZeroChars, 0, s, nextZeroValue, nonZeroChars.length);
189 c$.externalSortInt = Clazz.defineMethod (c$, "externalSortInt",
191 var length = arr.length;
192 var indices = jalview.util.QuickSort.makeIndexArray (length);
193 java.util.Arrays.sort (indices, new jalview.util.QuickSort.IntComparator (arr));
194 var sortedInts = Clazz.newIntArray (length, 0);
195 var sortedChars = Clazz.newCharArray (s.length, '\0');
196 for (var i = 0; i < length; i++) {
197 sortedInts[i] = arr[indices[i]];
198 sortedChars[i] = s[indices[i]];
200 System.arraycopy (sortedInts, 0, arr, 0, length);
201 System.arraycopy (sortedChars, 0, s, 0, s.length);
204 c$ = Clazz.decorateAsClass (function () {
206 Clazz.instantialize (this, arguments);
207 }, jalview.util.QuickSort, "FloatComparator", null, java.util.Comparator);
208 Clazz.makeConstructor (c$,
212 Clazz.overrideMethod (c$, "compare",
214 return Float.compare (this.values[a.intValue ()], this.values[b]);
215 }, "Integer,Integer");
218 c$ = Clazz.decorateAsClass (function () {
220 Clazz.instantialize (this, arguments);
221 }, jalview.util.QuickSort, "IntComparator", null, java.util.Comparator);
222 Clazz.makeConstructor (c$,
226 Clazz.overrideMethod (c$, "compare",
228 return Integer.compare (this.values[a], this.values[b]);
229 }, "Integer,Integer");