public class ArrayUtils extends Object
Constructor and Description |
---|
ArrayUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
sort(int[] keys,
int[] values)
Sorts the keys in an increasing order.
|
static void |
sort(int[] keys,
int[] values,
int offset,
int length)
Sorts a range from the keys in an increasing order.
|
static void |
sortDesc(long[] keys,
int[] values)
Sorts the keys in an decreasing order.
|
static void |
sortDesc(long[] keys,
int[] values,
long[] tmpa,
int[] tmpb)
Sorts the keys in an decreasing order.
|
public static void sort(int[] keys, int[] values)
A mixture of several sorting algorithms is used:
A radix sort performs better on the numeric data we sort, but requires additional storage to perform the sorting. Therefore only the not-very-large parts produced by a quick sort are sorted with radix sort. An insertion sort is used to sort the smallest arrays, where the the overhead of the radix sort is also bigger
keys
- the keys for sortingvalues
- the values to be swapped with the corresponding keyspublic static void sortDesc(long[] keys, int[] values)
A mixture of several sorting algorithms is used:
A radix sort performs better on the numeric data we sort, but requires additional storage to perform the sorting. Therefore only the not-very-large parts produced by a quick sort are sorted with radix sort. An insertion sort is used to sort the smallest arrays, where the the overhead of the radix sort is also bigger
keys
- the keys for sortingvalues
- the values to be swapped with the corresponding keyspublic static void sortDesc(long[] keys, int[] values, long[] tmpa, int[] tmpb)
A mixture of several sorting algorithms is used:
A radix sort performs better on the numeric data we sort, but requires additional storage to perform the sorting. Therefore only the not-very-large parts produced by a quick sort are sorted with radix sort. An insertion sort is used to sort the smallest arrays, where the the overhead of the radix sort is also bigger
This version of the method allows the temporarily needed arrays for the radix sort to be provided externally - tempa and tempb. This saves unnecessary array creation and cleanup
keys
- the keys for sortingvalues
- the values to be swapped with the corresponding keystmpa
- a temporary buffer at least as big as the keystmpb
- a temporary buffer at least as big as the keys/valuespublic static void sort(int[] keys, int[] values, int offset, int length)
A mixture of several sorting algorithms is used:
A radix sort performs better on the numeric data we sort, but requires additional storage to perform the sorting. Therefore only the not-very-large parts produced by a quick sort are sorted with radix sort. An insertion sort is used to sort the smallest arrays, where the the overhead of the radix sort is also bigger
keys
- the keys for sortingvalues
- the values to be swapped with the corresponding keysoffset
- where in the arrays to start sortinglength
- how many keys (and values) from the offset to sort