1 |
/* Arrays.java -- Utility class with methods to operate on arrays |
/* Arrays.java -- Utility class with methods to operate on arrays |
2 |
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. |
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 |
3 |
|
Free Software Foundation, Inc. |
4 |
|
|
5 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
6 |
|
|
969 |
{ |
{ |
970 |
if (fromIndex > toIndex) |
if (fromIndex > toIndex) |
971 |
throw new IllegalArgumentException(); |
throw new IllegalArgumentException(); |
972 |
|
if (fromIndex < 0) |
973 |
|
throw new ArrayIndexOutOfBoundsException(); |
974 |
qsort(a, fromIndex, toIndex - fromIndex); |
qsort(a, fromIndex, toIndex - fromIndex); |
975 |
} |
} |
976 |
|
|
1031 |
if (count <= 7) |
if (count <= 7) |
1032 |
{ |
{ |
1033 |
for (int i = from + 1; i < from + count; i++) |
for (int i = from + 1; i < from + count; i++) |
1034 |
for (int j = i; j > 0 && array[j - 1] > array[j]; j--) |
for (int j = i; j > from && array[j - 1] > array[j]; j--) |
1035 |
swap(j, j - 1, array); |
swap(j, j - 1, array); |
1036 |
return; |
return; |
1037 |
} |
} |
1133 |
{ |
{ |
1134 |
if (fromIndex > toIndex) |
if (fromIndex > toIndex) |
1135 |
throw new IllegalArgumentException(); |
throw new IllegalArgumentException(); |
1136 |
|
if (fromIndex < 0) |
1137 |
|
throw new ArrayIndexOutOfBoundsException(); |
1138 |
qsort(a, fromIndex, toIndex - fromIndex); |
qsort(a, fromIndex, toIndex - fromIndex); |
1139 |
} |
} |
1140 |
|
|
1195 |
if (count <= 7) |
if (count <= 7) |
1196 |
{ |
{ |
1197 |
for (int i = from + 1; i < from + count; i++) |
for (int i = from + 1; i < from + count; i++) |
1198 |
for (int j = i; j > 0 && array[j - 1] > array[j]; j--) |
for (int j = i; j > from && array[j - 1] > array[j]; j--) |
1199 |
swap(j, j - 1, array); |
swap(j, j - 1, array); |
1200 |
return; |
return; |
1201 |
} |
} |
1297 |
{ |
{ |
1298 |
if (fromIndex > toIndex) |
if (fromIndex > toIndex) |
1299 |
throw new IllegalArgumentException(); |
throw new IllegalArgumentException(); |
1300 |
|
if (fromIndex < 0) |
1301 |
|
throw new ArrayIndexOutOfBoundsException(); |
1302 |
qsort(a, fromIndex, toIndex - fromIndex); |
qsort(a, fromIndex, toIndex - fromIndex); |
1303 |
} |
} |
1304 |
|
|
1359 |
if (count <= 7) |
if (count <= 7) |
1360 |
{ |
{ |
1361 |
for (int i = from + 1; i < from + count; i++) |
for (int i = from + 1; i < from + count; i++) |
1362 |
for (int j = i; j > 0 && array[j - 1] > array[j]; j--) |
for (int j = i; j > from && array[j - 1] > array[j]; j--) |
1363 |
swap(j, j - 1, array); |
swap(j, j - 1, array); |
1364 |
return; |
return; |
1365 |
} |
} |
1366 |
|
|
1461 |
{ |
{ |
1462 |
if (fromIndex > toIndex) |
if (fromIndex > toIndex) |
1463 |
throw new IllegalArgumentException(); |
throw new IllegalArgumentException(); |
1464 |
|
if (fromIndex < 0) |
1465 |
|
throw new ArrayIndexOutOfBoundsException(); |
1466 |
qsort(a, fromIndex, toIndex - fromIndex); |
qsort(a, fromIndex, toIndex - fromIndex); |
1467 |
} |
} |
1468 |
|
|
1535 |
if (count <= 7) |
if (count <= 7) |
1536 |
{ |
{ |
1537 |
for (int i = from + 1; i < from + count; i++) |
for (int i = from + 1; i < from + count; i++) |
1538 |
for (int j = i; j > 0 && array[j - 1] > array[j]; j--) |
for (int j = i; j > from && array[j - 1] > array[j]; j--) |
1539 |
swap(j, j - 1, array); |
swap(j, j - 1, array); |
1540 |
return; |
return; |
1541 |
} |
} |
1637 |
{ |
{ |
1638 |
if (fromIndex > toIndex) |
if (fromIndex > toIndex) |
1639 |
throw new IllegalArgumentException(); |
throw new IllegalArgumentException(); |
1640 |
|
if (fromIndex < 0) |
1641 |
|
throw new ArrayIndexOutOfBoundsException(); |
1642 |
qsort(a, fromIndex, toIndex - fromIndex); |
qsort(a, fromIndex, toIndex - fromIndex); |
1643 |
} |
} |
1644 |
|
|
1711 |
if (count <= 7) |
if (count <= 7) |
1712 |
{ |
{ |
1713 |
for (int i = from + 1; i < from + count; i++) |
for (int i = from + 1; i < from + count; i++) |
1714 |
for (int j = i; j > 0 && array[j - 1] > array[j]; j--) |
for (int j = i; j > from && array[j - 1] > array[j]; j--) |
1715 |
swap(j, j - 1, array); |
swap(j, j - 1, array); |
1716 |
return; |
return; |
1717 |
} |
} |
1813 |
{ |
{ |
1814 |
if (fromIndex > toIndex) |
if (fromIndex > toIndex) |
1815 |
throw new IllegalArgumentException(); |
throw new IllegalArgumentException(); |
1816 |
|
if (fromIndex < 0) |
1817 |
|
throw new ArrayIndexOutOfBoundsException(); |
1818 |
qsort(a, fromIndex, toIndex - fromIndex); |
qsort(a, fromIndex, toIndex - fromIndex); |
1819 |
} |
} |
1820 |
|
|
1878 |
{ |
{ |
1879 |
for (int i = from + 1; i < from + count; i++) |
for (int i = from + 1; i < from + count; i++) |
1880 |
for (int j = i; |
for (int j = i; |
1881 |
j > 0 && Float.compare(array[j - 1], array[j]) > 0; |
j > from && Float.compare(array[j - 1], array[j]) > 0; |
1882 |
j--) |
j--) |
1883 |
{ |
{ |
1884 |
swap(j, j - 1, array); |
swap(j, j - 1, array); |
1983 |
{ |
{ |
1984 |
if (fromIndex > toIndex) |
if (fromIndex > toIndex) |
1985 |
throw new IllegalArgumentException(); |
throw new IllegalArgumentException(); |
1986 |
|
if (fromIndex < 0) |
1987 |
|
throw new ArrayIndexOutOfBoundsException(); |
1988 |
qsort(a, fromIndex, toIndex - fromIndex); |
qsort(a, fromIndex, toIndex - fromIndex); |
1989 |
} |
} |
1990 |
|
|
2048 |
{ |
{ |
2049 |
for (int i = from + 1; i < from + count; i++) |
for (int i = from + 1; i < from + count; i++) |
2050 |
for (int j = i; |
for (int j = i; |
2051 |
j > 0 && Double.compare(array[j - 1], array[j]) > 0; |
j > from && Double.compare(array[j - 1], array[j]) > 0; |
2052 |
j--) |
j--) |
2053 |
{ |
{ |
2054 |
swap(j, j - 1, array); |
swap(j, j - 1, array); |
2218 |
if (fromIndex > toIndex) |
if (fromIndex > toIndex) |
2219 |
throw new IllegalArgumentException("fromIndex " + fromIndex |
throw new IllegalArgumentException("fromIndex " + fromIndex |
2220 |
+ " > toIndex " + toIndex); |
+ " > toIndex " + toIndex); |
2221 |
|
if (fromIndex < 0) |
2222 |
|
throw new ArrayIndexOutOfBoundsException(); |
2223 |
|
|
2224 |
// In general, the code attempts to be simple rather than fast, the |
// In general, the code attempts to be simple rather than fast, the |
2225 |
// idea being that a good optimising JIT will be able to optimise it |
// idea being that a good optimising JIT will be able to optimise it |