Class ArrayUtils
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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.
-
Constructor Details
-
ArrayUtils
public ArrayUtils()
-
-
Method Details
-
sort
public static void sort(int[] keys, int[] values) Sorts the keys in an increasing order. Elements key[i] and values[i] are always swapped together in the corresponding arrays.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
- Parameters:
keys
- the keys for sortingvalues
- the values to be swapped with the corresponding keys
-
sortDesc
public static void sortDesc(long[] keys, int[] values) Sorts the keys in an decreasing order. Elements key[i] and values[i] are always swapped together in the corresponding arrays.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
- Parameters:
keys
- the keys for sortingvalues
- the values to be swapped with the corresponding keys
-
sortDesc
public static void sortDesc(long[] keys, int[] values, long[] tmpa, int[] tmpb) Sorts the keys in an decreasing order. Elements key[i] and values[i] are always swapped together in the corresponding arrays.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
- Parameters:
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/values
-
sort
public static void sort(int[] keys, int[] values, int offset, int length) Sorts a range from the keys in an increasing order. Elements key[i] and values[i] are always swapped together in the corresponding arrays.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
- Parameters:
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
-