1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.util; |
22 |
|
|
23 |
|
import java.util.Arrays; |
24 |
|
import java.util.Comparator; |
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
@author |
31 |
|
|
32 |
|
|
|
|
| 89.3% |
Uncovered Elements: 33 (309) |
Complexity: 56 |
Complexity Density: 0.26 |
|
33 |
|
public class QuickSort |
34 |
|
{ |
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 3 |
Complexity Density: 1 |
|
39 |
|
static class FloatComparator implements Comparator<Integer> |
40 |
|
{ |
41 |
|
private final float[] values; |
42 |
|
|
43 |
|
private boolean ascending; |
44 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
45 |
3 |
FloatComparator(float[] v, boolean asc)... |
46 |
|
{ |
47 |
3 |
values = v; |
48 |
3 |
ascending = asc; |
49 |
|
} |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
51 |
212 |
@Override... |
52 |
|
public int compare(Integer o1, Integer o2) |
53 |
|
{ |
54 |
212 |
return ascending |
55 |
|
? Float.compare(values[o1.intValue()], values[o2.intValue()]) |
56 |
|
: Float.compare(values[o2.intValue()], values[o1.intValue()]); |
57 |
|
} |
58 |
|
} |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
64 |
|
static class DoubleComparator implements Comparator<Integer> |
65 |
|
{ |
66 |
|
private final double[] values; |
67 |
|
|
68 |
|
private boolean ascending; |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
70 |
5 |
DoubleComparator(double[] v, boolean asc)... |
71 |
|
{ |
72 |
5 |
values = v; |
73 |
5 |
ascending = asc; |
74 |
|
} |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
76 |
26 |
@Override... |
77 |
|
public int compare(Integer o1, Integer o2) |
78 |
|
{ |
79 |
26 |
if (ascending) |
80 |
|
{ |
81 |
21 |
return Double.compare(values[o1.intValue()], values[o2.intValue()]); |
82 |
|
} |
83 |
|
else |
84 |
|
{ |
85 |
5 |
return Double.compare(values[o2.intValue()], values[o1.intValue()]); |
86 |
|
} |
87 |
|
} |
88 |
|
} |
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 3 |
Complexity Density: 1 |
|
94 |
|
static class IntComparator implements Comparator<Integer> |
95 |
|
{ |
96 |
|
private final int[] values; |
97 |
|
|
98 |
|
private boolean ascending; |
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
100 |
163124 |
IntComparator(int[] v, boolean asc)... |
101 |
|
{ |
102 |
163124 |
values = v; |
103 |
163125 |
ascending = asc; |
104 |
|
} |
105 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
106 |
265637 |
@Override... |
107 |
|
public int compare(Integer o1, Integer o2) |
108 |
|
{ |
109 |
265641 |
return ascending |
110 |
|
? Integer.compare(values[o1.intValue()], |
111 |
|
values[o2.intValue()]) |
112 |
|
: Integer.compare(values[o2.intValue()], |
113 |
|
values[o1.intValue()]); |
114 |
|
} |
115 |
|
} |
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 3 |
Complexity Density: 1 |
|
121 |
|
static class ExternalComparator implements Comparator<Integer> |
122 |
|
{ |
123 |
|
private final Comparable[] values; |
124 |
|
|
125 |
|
private boolean ascending; |
126 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
127 |
2 |
ExternalComparator(Comparable[] v, boolean asc)... |
128 |
|
{ |
129 |
2 |
values = v; |
130 |
2 |
ascending = asc; |
131 |
|
} |
132 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
133 |
16 |
@Override... |
134 |
|
public int compare(Integer o1, Integer o2) |
135 |
|
{ |
136 |
16 |
return ascending |
137 |
|
? values[o1.intValue()].compareTo(values[o2.intValue()]) |
138 |
|
: values[o2.intValue()].compareTo(values[o1.intValue()]); |
139 |
|
} |
140 |
|
} |
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
@param |
147 |
|
@param |
148 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
149 |
101 |
public static void sort(int[] arr, Object[] s)... |
150 |
|
{ |
151 |
101 |
sort(arr, 0, arr.length - 1, s); |
152 |
|
} |
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
@param |
159 |
|
@param |
160 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
161 |
1 |
public static void sort(float[] arr, Object[] s)... |
162 |
|
{ |
163 |
1 |
sort(arr, 0, arr.length - 1, s); |
164 |
|
} |
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
@param |
171 |
|
@param |
172 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
173 |
1 |
public static void sort(double[] arr, Object[] s)... |
174 |
|
{ |
175 |
1 |
sort(arr, 0, arr.length - 1, s); |
176 |
|
} |
177 |
|
|
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
@param |
183 |
|
@param |
184 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
185 |
2027 |
public static void sort(String[] arr, Object[] s)... |
186 |
|
{ |
187 |
2027 |
stringSort(arr, 0, arr.length - 1, s); |
188 |
|
} |
189 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
190 |
6549 |
static void stringSort(String[] arr, int p, int r, Object[] s)... |
191 |
|
{ |
192 |
6549 |
int q; |
193 |
|
|
194 |
6549 |
if (p < r) |
195 |
|
{ |
196 |
2261 |
q = stringPartition(arr, p, r, s); |
197 |
2261 |
stringSort(arr, p, q, s); |
198 |
2261 |
stringSort(arr, q + 1, r, s); |
199 |
|
} |
200 |
|
} |
201 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
202 |
9 |
static void sort(float[] arr, int p, int r, Object[] s)... |
203 |
|
{ |
204 |
9 |
int q; |
205 |
|
|
206 |
9 |
if (p < r) |
207 |
|
{ |
208 |
4 |
q = partition(arr, p, r, s); |
209 |
4 |
sort(arr, p, q, s); |
210 |
4 |
sort(arr, q + 1, r, s); |
211 |
|
} |
212 |
|
} |
213 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
214 |
9 |
static void sort(double[] arr, int p, int r, Object[] s)... |
215 |
|
{ |
216 |
9 |
int q; |
217 |
|
|
218 |
9 |
if (p < r) |
219 |
|
{ |
220 |
4 |
q = partition(arr, p, r, s); |
221 |
4 |
sort(arr, p, q, s); |
222 |
4 |
sort(arr, q + 1, r, s); |
223 |
|
} |
224 |
|
} |
225 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
226 |
795 |
static void sort(int[] arr, int p, int r, Object[] s)... |
227 |
|
{ |
228 |
795 |
int q; |
229 |
|
|
230 |
795 |
if (p < r) |
231 |
|
{ |
232 |
347 |
q = partition(arr, p, r, s); |
233 |
347 |
sort(arr, p, q, s); |
234 |
347 |
sort(arr, q + 1, r, s); |
235 |
|
} |
236 |
|
} |
237 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 4 |
Complexity Density: 0.25 |
|
238 |
4 |
static int partition(float[] arr, int p, int r, Object[] s)... |
239 |
|
{ |
240 |
4 |
float x = arr[p]; |
241 |
4 |
int i = p - 1; |
242 |
4 |
int j = r + 1; |
243 |
|
|
244 |
4 |
while (true) |
245 |
|
{ |
246 |
7 |
do |
247 |
|
{ |
248 |
10 |
j = j - 1; |
249 |
10 |
} while (arr[j] > x); |
250 |
|
|
251 |
7 |
do |
252 |
|
{ |
253 |
8 |
i = i + 1; |
254 |
8 |
} while (arr[i] < x); |
255 |
|
|
256 |
7 |
if (i < j) |
257 |
|
{ |
258 |
3 |
float tmp = arr[i]; |
259 |
3 |
arr[i] = arr[j]; |
260 |
3 |
arr[j] = tmp; |
261 |
|
|
262 |
3 |
Object tmp2 = s[i]; |
263 |
3 |
s[i] = s[j]; |
264 |
3 |
s[j] = tmp2; |
265 |
|
} |
266 |
|
else |
267 |
|
{ |
268 |
4 |
return j; |
269 |
|
} |
270 |
|
} |
271 |
|
} |
272 |
|
|
|
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 4 |
Complexity Density: 0.25 |
|
273 |
0 |
static int partition(float[] arr, int p, int r, char[] s)... |
274 |
|
{ |
275 |
0 |
float x = arr[p]; |
276 |
0 |
int i = p - 1; |
277 |
0 |
int j = r + 1; |
278 |
|
|
279 |
0 |
while (true) |
280 |
|
{ |
281 |
0 |
do |
282 |
|
{ |
283 |
0 |
j = j - 1; |
284 |
0 |
} while (arr[j] > x); |
285 |
|
|
286 |
0 |
do |
287 |
|
{ |
288 |
0 |
i = i + 1; |
289 |
0 |
} while (arr[i] < x); |
290 |
|
|
291 |
0 |
if (i < j) |
292 |
|
{ |
293 |
0 |
float tmp = arr[i]; |
294 |
0 |
arr[i] = arr[j]; |
295 |
0 |
arr[j] = tmp; |
296 |
|
|
297 |
0 |
char tmp2 = s[i]; |
298 |
0 |
s[i] = s[j]; |
299 |
0 |
s[j] = tmp2; |
300 |
|
} |
301 |
|
else |
302 |
|
{ |
303 |
0 |
return j; |
304 |
|
} |
305 |
|
} |
306 |
|
} |
307 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 4 |
Complexity Density: 0.25 |
|
308 |
347 |
static int partition(int[] arr, int p, int r, Object[] s)... |
309 |
|
{ |
310 |
347 |
int x = arr[p]; |
311 |
347 |
int i = p - 1; |
312 |
347 |
int j = r + 1; |
313 |
|
|
314 |
347 |
while (true) |
315 |
|
{ |
316 |
537 |
do |
317 |
|
{ |
318 |
1285 |
j = j - 1; |
319 |
1285 |
} while (arr[j] > x); |
320 |
|
|
321 |
537 |
do |
322 |
|
{ |
323 |
652 |
i = i + 1; |
324 |
652 |
} while (arr[i] < x); |
325 |
|
|
326 |
537 |
if (i < j) |
327 |
|
{ |
328 |
190 |
int tmp = arr[i]; |
329 |
190 |
arr[i] = arr[j]; |
330 |
190 |
arr[j] = tmp; |
331 |
|
|
332 |
190 |
Object tmp2 = s[i]; |
333 |
190 |
s[i] = s[j]; |
334 |
190 |
s[j] = tmp2; |
335 |
|
} |
336 |
|
else |
337 |
|
{ |
338 |
347 |
return j; |
339 |
|
} |
340 |
|
} |
341 |
|
} |
342 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 4 |
Complexity Density: 0.25 |
|
343 |
4 |
static int partition(double[] arr, int p, int r, Object[] s)... |
344 |
|
{ |
345 |
4 |
double x = arr[p]; |
346 |
4 |
int i = p - 1; |
347 |
4 |
int j = r + 1; |
348 |
|
|
349 |
4 |
while (true) |
350 |
|
{ |
351 |
7 |
do |
352 |
|
{ |
353 |
10 |
j = j - 1; |
354 |
10 |
} while (arr[j] > x); |
355 |
|
|
356 |
7 |
do |
357 |
|
{ |
358 |
8 |
i = i + 1; |
359 |
8 |
} while (arr[i] < x); |
360 |
|
|
361 |
7 |
if (i < j) |
362 |
|
{ |
363 |
3 |
double tmp = arr[i]; |
364 |
3 |
arr[i] = arr[j]; |
365 |
3 |
arr[j] = tmp; |
366 |
|
|
367 |
3 |
Object tmp2 = s[i]; |
368 |
3 |
s[i] = s[j]; |
369 |
3 |
s[j] = tmp2; |
370 |
|
} |
371 |
|
else |
372 |
|
{ |
373 |
4 |
return j; |
374 |
|
} |
375 |
|
} |
376 |
|
} |
377 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 4 |
Complexity Density: 0.25 |
|
378 |
2261 |
static int stringPartition(String[] arr, int p, int r, Object[] s)... |
379 |
|
{ |
380 |
2261 |
String x = arr[p]; |
381 |
2261 |
int i = p - 1; |
382 |
2261 |
int j = r + 1; |
383 |
|
|
384 |
2261 |
while (true) |
385 |
|
{ |
386 |
4012 |
do |
387 |
|
{ |
388 |
5612 |
j = j - 1; |
389 |
5612 |
} while (arr[j].compareTo(x) < 0); |
390 |
|
|
391 |
4012 |
do |
392 |
|
{ |
393 |
4356 |
i = i + 1; |
394 |
4356 |
} while (arr[i].compareTo(x) > 0); |
395 |
|
|
396 |
4012 |
if (i < j) |
397 |
|
{ |
398 |
1751 |
String tmp = arr[i]; |
399 |
1751 |
arr[i] = arr[j]; |
400 |
1751 |
arr[j] = tmp; |
401 |
|
|
402 |
1751 |
Object tmp2 = s[i]; |
403 |
1751 |
s[i] = s[j]; |
404 |
1751 |
s[j] = tmp2; |
405 |
|
} |
406 |
|
else |
407 |
|
{ |
408 |
2261 |
return j; |
409 |
|
} |
410 |
|
} |
411 |
|
} |
412 |
|
|
413 |
|
|
414 |
|
|
415 |
|
|
416 |
|
|
417 |
|
|
418 |
|
|
419 |
|
@param |
420 |
|
@param |
421 |
|
|
|
|
| 94.4% |
Uncovered Elements: 2 (36) |
Complexity: 5 |
Complexity Density: 0.18 |
|
422 |
1 |
public static void sort(float[] arr, char[] s)... |
423 |
|
{ |
424 |
|
|
425 |
|
|
426 |
|
|
427 |
|
|
428 |
1 |
float[] f1 = new float[arr.length]; |
429 |
1 |
char[] s1 = new char[s.length]; |
430 |
1 |
int negativeCount = 0; |
431 |
1 |
int zerosCount = 0; |
432 |
1 |
int nextNonZeroValue = arr.length - 1; |
433 |
65 |
for (int i = 0; i < arr.length; i++) |
434 |
|
{ |
435 |
64 |
float val = arr[i]; |
436 |
64 |
if (val != 0f) |
437 |
|
{ |
438 |
3 |
f1[nextNonZeroValue] = val; |
439 |
3 |
s1[nextNonZeroValue] = s[i]; |
440 |
3 |
nextNonZeroValue--; |
441 |
3 |
if (val < 0f) |
442 |
|
{ |
443 |
1 |
negativeCount++; |
444 |
|
} |
445 |
|
} |
446 |
|
else |
447 |
|
{ |
448 |
61 |
f1[zerosCount] = val; |
449 |
61 |
s1[zerosCount] = s[i]; |
450 |
61 |
zerosCount++; |
451 |
|
} |
452 |
|
} |
453 |
1 |
int positiveCount = arr.length - zerosCount - negativeCount; |
454 |
|
|
455 |
1 |
if (zerosCount == arr.length) |
456 |
|
{ |
457 |
0 |
return; |
458 |
|
} |
459 |
|
|
460 |
|
|
461 |
|
|
462 |
|
|
463 |
1 |
float[] nonZeroFloats = Arrays.copyOfRange(f1, zerosCount, f1.length); |
464 |
1 |
char[] nonZeroChars = Arrays.copyOfRange(s1, zerosCount, s1.length); |
465 |
1 |
charSortByFloat(nonZeroFloats, nonZeroChars, true); |
466 |
|
|
467 |
|
|
468 |
|
|
469 |
|
|
470 |
|
|
471 |
1 |
System.arraycopy(f1, 0, arr, negativeCount, zerosCount); |
472 |
1 |
System.arraycopy(s1, 0, s, negativeCount, zerosCount); |
473 |
|
|
474 |
|
|
475 |
|
|
476 |
|
|
477 |
1 |
System.arraycopy(nonZeroFloats, 0, arr, 0, negativeCount); |
478 |
1 |
System.arraycopy(nonZeroChars, 0, s, 0, negativeCount); |
479 |
|
|
480 |
|
|
481 |
|
|
482 |
|
|
483 |
1 |
System.arraycopy(nonZeroFloats, negativeCount, arr, |
484 |
|
negativeCount + zerosCount, positiveCount); |
485 |
1 |
System.arraycopy(nonZeroChars, negativeCount, s, |
486 |
|
negativeCount + zerosCount, positiveCount); |
487 |
|
} |
488 |
|
|
489 |
|
|
490 |
|
|
491 |
|
|
492 |
|
|
493 |
|
@see |
494 |
|
|
495 |
|
|
496 |
|
@param |
497 |
|
@param |
498 |
|
@param |
499 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
500 |
3 |
public static void charSortByFloat(float[] arr, char[] s,... |
501 |
|
boolean ascending) |
502 |
|
{ |
503 |
3 |
final int length = arr.length; |
504 |
3 |
Integer[] indices = makeIndexArray(length); |
505 |
3 |
Arrays.sort(indices, new FloatComparator(arr, ascending)); |
506 |
|
|
507 |
|
|
508 |
|
|
509 |
|
|
510 |
3 |
float[] sortedFloats = new float[length]; |
511 |
3 |
char[] sortedChars = new char[s.length]; |
512 |
134 |
for (int i = 0; i < length; i++) |
513 |
|
{ |
514 |
131 |
sortedFloats[i] = arr[indices[i]]; |
515 |
131 |
sortedChars[i] = s[indices[i]]; |
516 |
|
} |
517 |
|
|
518 |
|
|
519 |
|
|
520 |
|
|
521 |
3 |
System.arraycopy(sortedFloats, 0, arr, 0, length); |
522 |
3 |
System.arraycopy(sortedChars, 0, s, 0, s.length); |
523 |
|
} |
524 |
|
|
525 |
|
|
526 |
|
|
527 |
|
|
528 |
|
@param |
529 |
|
@return |
530 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
531 |
163134 |
protected static Integer[] makeIndexArray(final int length)... |
532 |
|
{ |
533 |
163133 |
Integer[] indices = new Integer[length]; |
534 |
485480 |
for (int i = 0; i < length; i++) |
535 |
|
{ |
536 |
322349 |
indices[i] = i; |
537 |
|
} |
538 |
163134 |
return indices; |
539 |
|
} |
540 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
541 |
0 |
static void sort(float[] arr, int p, int r, char[] s)... |
542 |
|
{ |
543 |
0 |
int q; |
544 |
0 |
if (p < r) |
545 |
|
{ |
546 |
0 |
q = partition(arr, p, r, s); |
547 |
0 |
sort(arr, p, q, s); |
548 |
0 |
sort(arr, q + 1, r, s); |
549 |
|
} |
550 |
|
} |
551 |
|
|
552 |
|
|
553 |
|
|
554 |
|
|
555 |
|
|
556 |
|
|
557 |
|
|
558 |
|
@param |
559 |
|
@param |
560 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (36) |
Complexity: 5 |
Complexity Density: 0.18 |
|
561 |
166299 |
public static void sort(int[] arr, char[] s)... |
562 |
|
{ |
563 |
|
|
564 |
|
|
565 |
|
|
566 |
166298 |
int[] f1 = new int[arr.length]; |
567 |
166297 |
char[] s1 = new char[s.length]; |
568 |
166300 |
int negativeCount = 0; |
569 |
166300 |
int zerosCount = 0; |
570 |
166299 |
int nextNonZeroValue = arr.length - 1; |
571 |
609743 |
for (int i = 0; i < arr.length; i++) |
572 |
|
{ |
573 |
443448 |
int val = arr[i]; |
574 |
443459 |
if (val != 0f) |
575 |
|
{ |
576 |
322041 |
f1[nextNonZeroValue] = val; |
577 |
322042 |
s1[nextNonZeroValue] = s[i]; |
578 |
322042 |
nextNonZeroValue--; |
579 |
322040 |
if (val < 0) |
580 |
|
{ |
581 |
1 |
negativeCount++; |
582 |
|
} |
583 |
|
} |
584 |
|
else |
585 |
|
{ |
586 |
121418 |
f1[zerosCount] = val; |
587 |
121418 |
s1[zerosCount] = s[i]; |
588 |
121418 |
zerosCount++; |
589 |
|
} |
590 |
|
} |
591 |
166294 |
int positiveCount = arr.length - zerosCount - negativeCount; |
592 |
|
|
593 |
166294 |
if (zerosCount == arr.length) |
594 |
|
{ |
595 |
3179 |
return; |
596 |
|
} |
597 |
|
|
598 |
|
|
599 |
|
|
600 |
|
|
601 |
163115 |
int[] nonZeroInts = Arrays.copyOfRange(f1, zerosCount, f1.length); |
602 |
163119 |
char[] nonZeroChars = Arrays.copyOfRange(s1, zerosCount, s1.length); |
603 |
163116 |
charSortByInt(nonZeroInts, nonZeroChars, true); |
604 |
|
|
605 |
|
|
606 |
|
|
607 |
|
|
608 |
|
|
609 |
163115 |
System.arraycopy(f1, 0, arr, negativeCount, zerosCount); |
610 |
163116 |
System.arraycopy(s1, 0, s, negativeCount, zerosCount); |
611 |
|
|
612 |
|
|
613 |
|
|
614 |
|
|
615 |
163115 |
System.arraycopy(nonZeroInts, 0, arr, 0, negativeCount); |
616 |
163115 |
System.arraycopy(nonZeroChars, 0, s, 0, negativeCount); |
617 |
|
|
618 |
|
|
619 |
|
|
620 |
|
|
621 |
163118 |
System.arraycopy(nonZeroInts, negativeCount, arr, |
622 |
|
negativeCount + zerosCount, positiveCount); |
623 |
163119 |
System.arraycopy(nonZeroChars, negativeCount, s, |
624 |
|
negativeCount + zerosCount, positiveCount); |
625 |
|
} |
626 |
|
|
627 |
|
|
628 |
|
|
629 |
|
|
630 |
|
|
631 |
|
@see |
632 |
|
|
633 |
|
|
634 |
|
@param |
635 |
|
@param |
636 |
|
@param |
637 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
638 |
163121 |
public static void charSortByInt(int[] arr, char[] s, boolean ascending)... |
639 |
|
{ |
640 |
163120 |
final int length = arr.length; |
641 |
163123 |
Integer[] indices = makeIndexArray(length); |
642 |
163122 |
Arrays.sort(indices, new IntComparator(arr, ascending)); |
643 |
|
|
644 |
|
|
645 |
|
|
646 |
|
|
647 |
163119 |
int[] sortedInts = new int[length]; |
648 |
163120 |
char[] sortedChars = new char[s.length]; |
649 |
485292 |
for (int i = 0; i < length; i++) |
650 |
|
{ |
651 |
322169 |
sortedInts[i] = arr[indices[i]]; |
652 |
322173 |
sortedChars[i] = s[indices[i]]; |
653 |
|
} |
654 |
|
|
655 |
|
|
656 |
|
|
657 |
|
|
658 |
163122 |
System.arraycopy(sortedInts, 0, arr, 0, length); |
659 |
163118 |
System.arraycopy(sortedChars, 0, s, 0, s.length); |
660 |
|
} |
661 |
|
|
662 |
|
|
663 |
|
|
664 |
|
|
665 |
|
|
666 |
|
@see |
667 |
|
|
668 |
|
|
669 |
|
@param |
670 |
|
@param |
671 |
|
@param |
672 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
673 |
2 |
public static void sortByInt(int[] arr, Object[] s, boolean ascending)... |
674 |
|
{ |
675 |
2 |
final int length = arr.length; |
676 |
2 |
Integer[] indices = makeIndexArray(length); |
677 |
2 |
Arrays.sort(indices, new IntComparator(arr, ascending)); |
678 |
|
|
679 |
|
|
680 |
|
|
681 |
|
|
682 |
2 |
int[] sortedInts = new int[length]; |
683 |
2 |
Object[] sortedObjects = new Object[s.length]; |
684 |
12 |
for (int i = 0; i < length; i++) |
685 |
|
{ |
686 |
10 |
sortedInts[i] = arr[indices[i]]; |
687 |
10 |
sortedObjects[i] = s[indices[i]]; |
688 |
|
} |
689 |
|
|
690 |
|
|
691 |
|
|
692 |
|
|
693 |
2 |
System.arraycopy(sortedInts, 0, arr, 0, length); |
694 |
2 |
System.arraycopy(sortedObjects, 0, s, 0, s.length); |
695 |
|
} |
696 |
|
|
697 |
|
|
698 |
|
|
699 |
|
|
700 |
|
|
701 |
|
|
702 |
|
@see |
703 |
|
|
704 |
|
|
705 |
|
@param |
706 |
|
@param |
707 |
|
@param |
708 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
709 |
2 |
public static void sortByString(String[] arr, Object[] s,... |
710 |
|
boolean ascending) |
711 |
|
{ |
712 |
2 |
final int length = arr.length; |
713 |
2 |
Integer[] indices = makeIndexArray(length); |
714 |
2 |
Arrays.sort(indices, new ExternalComparator(arr, ascending)); |
715 |
|
|
716 |
|
|
717 |
|
|
718 |
|
|
719 |
2 |
String[] sortedStrings = new String[length]; |
720 |
2 |
Object[] sortedObjects = new Object[s.length]; |
721 |
12 |
for (int i = 0; i < length; i++) |
722 |
|
{ |
723 |
10 |
sortedStrings[i] = arr[indices[i]]; |
724 |
10 |
sortedObjects[i] = s[indices[i]]; |
725 |
|
} |
726 |
|
|
727 |
|
|
728 |
|
|
729 |
|
|
730 |
2 |
System.arraycopy(sortedStrings, 0, arr, 0, length); |
731 |
2 |
System.arraycopy(sortedObjects, 0, s, 0, s.length); |
732 |
|
} |
733 |
|
|
734 |
|
|
735 |
|
|
736 |
|
|
737 |
|
|
738 |
|
@see |
739 |
|
|
740 |
|
|
741 |
|
@param |
742 |
|
@param |
743 |
|
@param |
744 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
745 |
5 |
public static void sortByDouble(double[] arr, Object[] s,... |
746 |
|
boolean ascending) |
747 |
|
{ |
748 |
5 |
final int length = arr.length; |
749 |
5 |
Integer[] indices = makeIndexArray(length); |
750 |
5 |
Arrays.sort(indices, new DoubleComparator(arr, ascending)); |
751 |
|
|
752 |
|
|
753 |
|
|
754 |
|
|
755 |
5 |
double[] sortedDoubles = new double[length]; |
756 |
5 |
Object[] sortedObjects = new Object[s.length]; |
757 |
25 |
for (int i = 0; i < length; i++) |
758 |
|
{ |
759 |
20 |
sortedDoubles[i] = arr[indices[i]]; |
760 |
20 |
sortedObjects[i] = s[indices[i]]; |
761 |
|
} |
762 |
|
|
763 |
|
|
764 |
|
|
765 |
|
|
766 |
5 |
System.arraycopy(sortedDoubles, 0, arr, 0, length); |
767 |
5 |
System.arraycopy(sortedObjects, 0, s, 0, s.length); |
768 |
|
} |
769 |
|
} |