it.unimi.dsi.fastutil.chars
Class CharArrays

java.lang.Object
  extended by it.unimi.dsi.fastutil.chars.CharArrays

public class CharArrays
extends Object

A class providing static methods and objects that do useful things with type-specific arrays.

In particular, the ensureCapacity(), grow(), trim() and setLength() methods allow to handle arrays much like array lists. This can be very useful when efficiency (or syntactic simplicity) reasons make array lists unsuitable.

Note that BinIO and TextIO contain several methods make it possible to load and save arrays of primitive types as sequences of elements in DataInput format (i.e., not as objects) or as sequences of lines of text.

See Also:
Arrays

Field Summary
static char[] EMPTY_ARRAY
          A static, final, empty array.
static Hash.Strategy HASH_STRATEGY
          A type-specific content-based hash strategy for arrays.
static long ONEOVERPHI
          The inverse of the golden ratio times 216.
 
Method Summary
static int binarySearch(char[] a, char key)
          Searches an array for the specified value using the binary search algorithm.
static int binarySearch(char[] a, char key, CharComparator c)
          Searches an array for the specified value using the binary search algorithm and a specified comparator.
static int binarySearch(char[] a, int from, int to, char key)
          Searches a range of the specified array for the specified value using the binary search algorithm.
static int binarySearch(char[] a, int from, int to, char key, CharComparator c)
          Searches a range of the specified array for the specified value using the binary search algorithm and a specified comparator.
static char[] copy(char[] array)
          Returns a copy of an array.
static char[] copy(char[] array, int offset, int length)
          Returns a copy of a portion of an array.
static char[] ensureCapacity(char[] array, int length)
          Ensures that an array can contain the given number of entries.
static char[] ensureCapacity(char[] array, int length, int preserve)
          Ensures that an array can contain the given number of entries, preserving just a part of the array.
static void ensureFromTo(char[] a, int from, int to)
          Ensures that a range given by its first (inclusive) and last (exclusive) elements fits an array.
static void ensureOffsetLength(char[] a, int offset, int length)
          Ensures that a range given by an offset and a length fits an array.
static boolean equals(char[] a1, char[] a2)
          Returns true if the two arrays are elementwise equal.
static void fill(char[] array, char value)
          Fills the given array with the given value.
static void fill(char[] array, int from, int to, char value)
          Fills a portion of the given array with the given value.
static char[] grow(char[] array, int length)
          Grows the given array to the maximum between the given length and the current length divided by the golden ratio, provided that the given length is larger than the current length.
static char[] grow(char[] array, int length, int preserve)
          Grows the given array to the maximum between the given length and the current length divided by the golden ratio, provided that the given length is larger than the current length, preserving just a part of the array.
static void mergeSort(char[] a)
          Sorts an array according to the natural ascending order using mergesort.
static void mergeSort(char[] a, CharComparator comp)
          Sorts an array according to the order induced by the specified comparator using mergesort.
static void mergeSort(char[] a, int from, int to)
          Sorts the specified range of elements according to the natural ascending order using mergesort.
static void mergeSort(char[] a, int from, int to, char[] supp)
          Sorts the specified range of elements according to the natural ascending order using mergesort, using a given support array.
static void mergeSort(char[] a, int from, int to, CharComparator comp)
          Sorts the specified range of elements according to the order induced by the specified comparator using mergesort.
static void mergeSort(char[] a, int from, int to, CharComparator comp, char[] supp)
          Sorts the specified range of elements according to the order induced by the specified comparator using mergesort, using a given support array.
static void quickSort(char[] x)
          Sorts an array according to the natural ascending order using quicksort.
static void quickSort(char[] x, CharComparator comp)
          Sorts an array according to the order induced by the specified comparator using quicksort.
static void quickSort(char[] x, int from, int to)
          Sorts the specified range of elements according to the natural ascending order using quicksort.
static void quickSort(char[] x, int from, int to, CharComparator comp)
          Sorts the specified range of elements according to the order induced by the specified comparator using quicksort.
static void radixSort(char[] a)
          Sorts the specified array using radix sort.
static void radixSort(char[][] a)
          Sorts the specified array of arrays lexicographically using radix sort.
static void radixSort(char[][] a, int from, int to)
          Sorts the specified array of arrays lexicographically using radix sort.
static void radixSort(char[] a, char[] b)
          Sorts the specified pair of arrays lexicographically using radix sort.
static void radixSort(char[] a, char[] b, int from, int to)
          Sorts the specified pair of arrays lexicographically using radix sort.
static void radixSort(char[] a, int from, int to)
          Sorts the specified array using radix sort.
static void radixSortIndirect(int[] perm, char[] a, boolean stable)
          Sorts the specified array using indirect radix sort.
static void radixSortIndirect(int[] perm, char[] a, char[] b, boolean stable)
          Sorts the specified pair of arrays lexicographically using indirect radix sort.
static void radixSortIndirect(int[] perm, char[] a, char[] b, int from, int to, boolean stable)
          Sorts the specified pair of arrays lexicographically using indirect radix sort.
static void radixSortIndirect(int[] perm, char[] a, int from, int to, boolean stable)
          Sorts the specified array using indirect radix sort.
static char[] reverse(char[] a)
          Reverses the order of the elements in the specified array.
static char[] setLength(char[] array, int length)
          Sets the length of the given array.
static char[] shuffle(char[] a, int from, int to, Random random)
          Shuffles the specified array fragment using the specified pseudorandom number generator.
static char[] shuffle(char[] a, Random random)
          Shuffles the specified array using the specified pseudorandom number generator.
static char[] trim(char[] array, int length)
          Trims the given array to the given length.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ONEOVERPHI

public static final long ONEOVERPHI
The inverse of the golden ratio times 216.

See Also:
Constant Field Values

EMPTY_ARRAY

public static final char[] EMPTY_ARRAY
A static, final, empty array.


HASH_STRATEGY

public static final Hash.Strategy HASH_STRATEGY
A type-specific content-based hash strategy for arrays.

This hash strategy may be used in custom hash collections whenever keys are arrays, and they must be considered equal by content. This strategy will handle null correctly, and it is serializable.

Method Detail

ensureCapacity

public static char[] ensureCapacity(char[] array,
                                    int length)
Ensures that an array can contain the given number of entries.

If you cannot foresee whether this array will need again to be enlarged, you should probably use grow() instead.

Parameters:
array - an array.
length - the new minimum length for this array.
Returns:
array, if it contains length entries or more; otherwise, an array with length entries whose first array.length entries are the same as those of array.

ensureCapacity

public static char[] ensureCapacity(char[] array,
                                    int length,
                                    int preserve)
Ensures that an array can contain the given number of entries, preserving just a part of the array.

Parameters:
array - an array.
length - the new minimum length for this array.
preserve - the number of elements of the array that must be preserved in case a new allocation is necessary.
Returns:
array, if it can contain length entries or more; otherwise, an array with length entries whose first preserve entries are the same as those of array.

grow

public static char[] grow(char[] array,
                          int length)
Grows the given array to the maximum between the given length and the current length divided by the golden ratio, provided that the given length is larger than the current length.

Dividing by the golden ratio (φ) approximately increases the array length by 1.618. If you want complete control on the array growth, you should probably use ensureCapacity() instead.

Parameters:
array - an array.
length - the new minimum length for this array.
Returns:
array, if it can contain length entries; otherwise, an array with max(length,array.length/φ) entries whose first array.length entries are the same as those of array.

grow

public static char[] grow(char[] array,
                          int length,
                          int preserve)
Grows the given array to the maximum between the given length and the current length divided by the golden ratio, provided that the given length is larger than the current length, preserving just a part of the array.

Dividing by the golden ratio (φ) approximately increases the array length by 1.618. If you want complete control on the array growth, you should probably use ensureCapacity() instead.

Parameters:
array - an array.
length - the new minimum length for this array.
preserve - the number of elements of the array that must be preserved in case a new allocation is necessary.
Returns:
array, if it can contain length entries; otherwise, an array with max(length,array.length/φ) entries whose first preserve entries are the same as those of array.

trim

public static char[] trim(char[] array,
                          int length)
Trims the given array to the given length.

Parameters:
array - an array.
length - the new maximum length for the array.
Returns:
array, if it contains length entries or less; otherwise, an array with length entries whose entries are the same as the first length entries of array.

setLength

public static char[] setLength(char[] array,
                               int length)
Sets the length of the given array.

Parameters:
array - an array.
length - the new length for the array.
Returns:
array, if it contains exactly length entries; otherwise, if it contains more than length entries, an array with length entries whose entries are the same as the first length entries of array; otherwise, an array with length entries whose first array.length entries are the same as those of array.

copy

public static char[] copy(char[] array,
                          int offset,
                          int length)
Returns a copy of a portion of an array.

Parameters:
array - an array.
offset - the first element to copy.
length - the number of elements to copy.
Returns:
a new array containing length elements of array starting at offset.

copy

public static char[] copy(char[] array)
Returns a copy of an array.

Parameters:
array - an array.
Returns:
a copy of array.

fill

public static void fill(char[] array,
                        char value)
Fills the given array with the given value.

This method uses a backward loop. It is significantly faster than the corresponding method in Arrays.

Parameters:
array - an array.
value - the new value for all elements of the array.

fill

public static void fill(char[] array,
                        int from,
                        int to,
                        char value)
Fills a portion of the given array with the given value.

If possible (i.e., from is 0) this method uses a backward loop. In this case, it is significantly faster than the corresponding method in Arrays.

Parameters:
array - an array.
from - the starting index of the portion to fill (inclusive).
to - the end index of the portion to fill (exclusive).
value - the new value for all elements of the specified portion of the array.

equals

public static boolean equals(char[] a1,
                             char[] a2)
Returns true if the two arrays are elementwise equal.

This method uses a backward loop. It is significantly faster than the corresponding method in Arrays.

Parameters:
a1 - an array.
a2 - another array.
Returns:
true if the two arrays are of the same length, and their elements are equal.

ensureFromTo

public static void ensureFromTo(char[] a,
                                int from,
                                int to)
Ensures that a range given by its first (inclusive) and last (exclusive) elements fits an array.

This method may be used whenever an array range check is needed.

Parameters:
a - an array.
from - a start index (inclusive).
to - an end index (exclusive).
Throws:
IllegalArgumentException - if from is greater than to.
ArrayIndexOutOfBoundsException - if from or to are greater than the array length or negative.

ensureOffsetLength

public static void ensureOffsetLength(char[] a,
                                      int offset,
                                      int length)
Ensures that a range given by an offset and a length fits an array.

This method may be used whenever an array range check is needed.

Parameters:
a - an array.
offset - a start index.
length - a length (the number of elements in the range).
Throws:
IllegalArgumentException - if length is negative.
ArrayIndexOutOfBoundsException - if offset is negative or offset+length is greater than the array length.

quickSort

public static void quickSort(char[] x,
                             int from,
                             int to,
                             CharComparator comp)
Sorts the specified range of elements according to the order induced by the specified comparator using quicksort.

The sorting algorithm is a tuned quicksort adapted from Jon L. Bentley and M. Douglas McIlroy, “Engineering a Sort Function”, Software: Practice and Experience, 23(11), pages 1249−1265, 1993.

Parameters:
x - the array to be sorted.
from - the index of the first element (inclusive) to be sorted.
to - the index of the last element (exclusive) to be sorted.
comp - the comparator to determine the sorting order.

quickSort

public static void quickSort(char[] x,
                             CharComparator comp)
Sorts an array according to the order induced by the specified comparator using quicksort.

The sorting algorithm is a tuned quicksort adapted from Jon L. Bentley and M. Douglas McIlroy, “Engineering a Sort Function”, Software: Practice and Experience, 23(11), pages 1249−1265, 1993.

Parameters:
x - the array to be sorted.
comp - the comparator to determine the sorting order.

quickSort

public static void quickSort(char[] x,
                             int from,
                             int to)
Sorts the specified range of elements according to the natural ascending order using quicksort.

The sorting algorithm is a tuned quicksort adapted from Jon L. Bentley and M. Douglas McIlroy, “Engineering a Sort Function”, Software: Practice and Experience, 23(11), pages 1249−1265, 1993.

Parameters:
x - the array to be sorted.
from - the index of the first element (inclusive) to be sorted.
to - the index of the last element (exclusive) to be sorted.

quickSort

public static void quickSort(char[] x)
Sorts an array according to the natural ascending order using quicksort.

The sorting algorithm is a tuned quicksort adapted from Jon L. Bentley and M. Douglas McIlroy, “Engineering a Sort Function”, Software: Practice and Experience, 23(11), pages 1249−1265, 1993.

Parameters:
x - the array to be sorted.

mergeSort

public static void mergeSort(char[] a,
                             int from,
                             int to,
                             char[] supp)
Sorts the specified range of elements according to the natural ascending order using mergesort, using a given support array.

This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort. Moreover, no support arrays will be allocated.

Parameters:
a - the array to be sorted.
from - the index of the first element (inclusive) to be sorted.
to - the index of the last element (exclusive) to be sorted.
supp - a support array, at least as large as a.

mergeSort

public static void mergeSort(char[] a,
                             int from,
                             int to)
Sorts the specified range of elements according to the natural ascending order using mergesort.

This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort. An array as large as a will be allocated by this method.

Parameters:
a - the array to be sorted.
from - the index of the first element (inclusive) to be sorted.
to - the index of the last element (exclusive) to be sorted.

mergeSort

public static void mergeSort(char[] a)
Sorts an array according to the natural ascending order using mergesort.

This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort. An array as large as a will be allocated by this method.

Parameters:
a - the array to be sorted.

mergeSort

public static void mergeSort(char[] a,
                             int from,
                             int to,
                             CharComparator comp,
                             char[] supp)
Sorts the specified range of elements according to the order induced by the specified comparator using mergesort, using a given support array.

This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort. Moreover, no support arrays will be allocated.

Parameters:
a - the array to be sorted.
from - the index of the first element (inclusive) to be sorted.
to - the index of the last element (exclusive) to be sorted.
comp - the comparator to determine the sorting order.
supp - a support array, at least as large as a.

mergeSort

public static void mergeSort(char[] a,
                             int from,
                             int to,
                             CharComparator comp)
Sorts the specified range of elements according to the order induced by the specified comparator using mergesort.

This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort. An array as large as a will be allocated by this method.

Parameters:
a - the array to be sorted.
from - the index of the first element (inclusive) to be sorted.
to - the index of the last element (exclusive) to be sorted.
comp - the comparator to determine the sorting order.

mergeSort

public static void mergeSort(char[] a,
                             CharComparator comp)
Sorts an array according to the order induced by the specified comparator using mergesort.

This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort. An array as large as a will be allocated by this method.

Parameters:
a - the array to be sorted.
comp - the comparator to determine the sorting order.

binarySearch

public static int binarySearch(char[] a,
                               int from,
                               int to,
                               char key)
Searches a range of the specified array for the specified value using the binary search algorithm. The range must be sorted prior to making this call. If it is not sorted, the results are undefined. If the range contains multiple elements with the specified value, there is no guarantee which one will be found.

Parameters:
a - the array to be searched.
from - the index of the first element (inclusive) to be searched.
to - the index of the last element (exclusive) to be searched.
key - the value to be searched for.
Returns:
index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1). The insertion point is defined as the the point at which the value would be inserted into the array: the index of the first element greater than the key, or the length of the array, if all elements in the array are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
See Also:
Arrays

binarySearch

public static int binarySearch(char[] a,
                               char key)
Searches an array for the specified value using the binary search algorithm. The range must be sorted prior to making this call. If it is not sorted, the results are undefined. If the range contains multiple elements with the specified value, there is no guarantee which one will be found.

Parameters:
a - the array to be searched.
key - the value to be searched for.
Returns:
index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1). The insertion point is defined as the the point at which the value would be inserted into the array: the index of the first element greater than the key, or the length of the array, if all elements in the array are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
See Also:
Arrays

binarySearch

public static int binarySearch(char[] a,
                               int from,
                               int to,
                               char key,
                               CharComparator c)
Searches a range of the specified array for the specified value using the binary search algorithm and a specified comparator. The range must be sorted following the comparator prior to making this call. If it is not sorted, the results are undefined. If the range contains multiple elements with the specified value, there is no guarantee which one will be found.

Parameters:
a - the array to be searched.
from - the index of the first element (inclusive) to be searched.
to - the index of the last element (exclusive) to be searched.
key - the value to be searched for.
c - a comparator.
Returns:
index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1). The insertion point is defined as the the point at which the value would be inserted into the array: the index of the first element greater than the key, or the length of the array, if all elements in the array are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
See Also:
Arrays

binarySearch

public static int binarySearch(char[] a,
                               char key,
                               CharComparator c)
Searches an array for the specified value using the binary search algorithm and a specified comparator. The range must be sorted following the comparator prior to making this call. If it is not sorted, the results are undefined. If the range contains multiple elements with the specified value, there is no guarantee which one will be found.

Parameters:
a - the array to be searched.
key - the value to be searched for.
c - a comparator.
Returns:
index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1). The insertion point is defined as the the point at which the value would be inserted into the array: the index of the first element greater than the key, or the length of the array, if all elements in the array are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
See Also:
Arrays

radixSort

public static void radixSort(char[] a)
Sorts the specified array using radix sort.

The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, Keith Bostic and M. Douglas McIlroy, “Engineering radix sort”, Computing Systems, 6(1), pages 5−27 (1993), and further improved using the digit-oracle idea described by Juha Kärkkäinen and Tommi Rantala in “Engineering radix sort for strings”, String Processing and Information Retrieval, 15th International Symposium, volume 5280 of Lecture Notes in Computer Science, pages 3−14, Springer (2008).

This implementation is significantly faster than quicksort already at small sizes (say, more than 10000 elements), but it can only sort in ascending order. It will allocate a support array of bytes with the same number of elements as the array to be sorted.

Parameters:
a - the array to be sorted.

radixSort

public static void radixSort(char[] a,
                             int from,
                             int to)
Sorts the specified array using radix sort.

The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, Keith Bostic and M. Douglas McIlroy, “Engineering radix sort”, Computing Systems, 6(1), pages 5−27 (1993), and further improved using the digit-oracle idea described by Juha Kärkkäinen and Tommi Rantala in “Engineering radix sort for strings”, String Processing and Information Retrieval, 15th International Symposium, volume 5280 of Lecture Notes in Computer Science, pages 3−14, Springer (2008).

This implementation is significantly faster than quicksort already at small sizes (say, more than 10000 elements), but it can only sort in ascending order. It will allocate a support array of bytes with the same number of elements as the array to be sorted.

Parameters:
a - the array to be sorted.
from - the index of the first element (inclusive) to be sorted.
to - the index of the last element (exclusive) to be sorted.

radixSortIndirect

public static void radixSortIndirect(int[] perm,
                                     char[] a,
                                     boolean stable)
Sorts the specified array using indirect radix sort.

The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, Keith Bostic and M. Douglas McIlroy, “Engineering radix sort”, Computing Systems, 6(1), pages 5−27 (1993), and further improved using the digit-oracle idea described by Juha Kärkkäinen and Tommi Rantala in “Engineering radix sort for strings”, String Processing and Information Retrieval, 15th International Symposium, volume 5280 of Lecture Notes in Computer Science, pages 3−14, Springer (2008).

This method implement an indirect sort. The elements of perm (which must be exactly the numbers in the interval [0..perm.length)) will be permuted so that a[ perm[ i ] ] <= a[ perm[ i + 1 ] ].

This implementation is significantly faster than quicksort (unstable) or mergesort (stable) already at small sizes (say, more than 10000 elements), but it can only sort in ascending order. It will allocate a support array of bytes with the same number of elements as the array to be sorted, and, in the stable case, a further support array as large as perm (note that the stable version is slightly faster).

Parameters:
perm - a permutation array indexing a.
a - the array to be sorted.
stable - whether the sorting algorithm should be stable.

radixSortIndirect

public static void radixSortIndirect(int[] perm,
                                     char[] a,
                                     int from,
                                     int to,
                                     boolean stable)
Sorts the specified array using indirect radix sort.

The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, Keith Bostic and M. Douglas McIlroy, “Engineering radix sort”, Computing Systems, 6(1), pages 5−27 (1993), and further improved using the digit-oracle idea described by Juha Kärkkäinen and Tommi Rantala in “Engineering radix sort for strings”, String Processing and Information Retrieval, 15th International Symposium, volume 5280 of Lecture Notes in Computer Science, pages 3−14, Springer (2008).

This method implement an indirect sort. The elements of perm (which must be exactly the numbers in the interval [0..perm.length)) will be permuted so that a[ perm[ i ] ] <= a[ perm[ i + 1 ] ].

This implementation is significantly faster than quicksort (unstable) or mergesort (stable) already at small sizes (say, more than 10000 elements), but it can only sort in ascending order. It will allocate a support array of bytes with the same number of elements as the array to be sorted, and, in the stable case, a further support array as large as perm (note that the stable version is slightly faster).

Parameters:
perm - a permutation array indexing a.
a - the array to be sorted.
from - the index of the first element of perm (inclusive) to be permuted.
to - the index of the last element of perm (exclusive) to be permuted.
stable - whether the sorting algorithm should be stable.

radixSort

public static void radixSort(char[] a,
                             char[] b)
Sorts the specified pair of arrays lexicographically using radix sort.

The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, Keith Bostic and M. Douglas McIlroy, “Engineering radix sort”, Computing Systems, 6(1), pages 5−27 (1993), and further improved using the digit-oracle idea described by Juha Kärkkäinen and Tommi Rantala in “Engineering radix sort for strings”, String Processing and Information Retrieval, 15th International Symposium, volume 5280 of Lecture Notes in Computer Science, pages 3−14, Springer (2008).

This method implements a lexicographical sorting of the arguments. Pairs of elements in the same position in the two provided arrays will be considered a single key, and permuted accordingly. In the end, either a[ i ] < a[ i + 1 ] or a[ i ] == a[ i + 1 ] and b[ i ] <= b[ i + 1 ].

This implementation is significantly faster than quicksort already at small sizes (say, more than 10000 elements), but it can only sort in ascending order. It will allocate a support array of bytes with the same number of elements as the arrays to be sorted.

Parameters:
a - the first array to be sorted.
b - the second array to be sorted.

radixSort

public static void radixSort(char[] a,
                             char[] b,
                             int from,
                             int to)
Sorts the specified pair of arrays lexicographically using radix sort.

The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, Keith Bostic and M. Douglas McIlroy, “Engineering radix sort”, Computing Systems, 6(1), pages 5−27 (1993), and further improved using the digit-oracle idea described by Juha Kärkkäinen and Tommi Rantala in “Engineering radix sort for strings”, String Processing and Information Retrieval, 15th International Symposium, volume 5280 of Lecture Notes in Computer Science, pages 3−14, Springer (2008).

This method implements a lexicographical sorting of the arguments. Pairs of elements in the same position in the two provided arrays will be considered a single key, and permuted accordingly. In the end, either a[ i ] < a[ i + 1 ] or a[ i ] == a[ i + 1 ] and b[ i ] <= b[ i + 1 ].

This implementation is significantly faster than quicksort already at small sizes (say, more than 10000 elements), but it can only sort in ascending order. It will allocate a support array of bytes with the same number of elements as the arrays to be sorted.

Parameters:
a - the first array to be sorted.
b - the second array to be sorted.
from - the index of the first element (inclusive) to be sorted.
to - the index of the last element (exclusive) to be sorted.

radixSortIndirect

public static void radixSortIndirect(int[] perm,
                                     char[] a,
                                     char[] b,
                                     boolean stable)
Sorts the specified pair of arrays lexicographically using indirect radix sort.

The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, Keith Bostic and M. Douglas McIlroy, “Engineering radix sort”, Computing Systems, 6(1), pages 5−27 (1993), and further improved using the digit-oracle idea described by Juha Kärkkäinen and Tommi Rantala in “Engineering radix sort for strings”, String Processing and Information Retrieval, 15th International Symposium, volume 5280 of Lecture Notes in Computer Science, pages 3−14, Springer (2008).

This method implement an indirect sort. The elements of perm (which must be exactly the numbers in the interval [0..perm.length)) will be permuted so that a[ perm[ i ] ] <= a[ perm[ i + 1 ] ].

This implementation is significantly faster than quicksort (unstable) or mergesort (stable) already at small sizes (say, more than 10000 elements), but it can only sort in ascending order. It will allocate a support array of bytes with the same number of elements as the array to be sorted, and, in the stable case, a further support array as large as perm (note that the stable version is slightly faster).

Parameters:
perm - a permutation array indexing a.
a - the array to be sorted.
b - the second array to be sorted.
stable - whether the sorting algorithm should be stable.

radixSortIndirect

public static void radixSortIndirect(int[] perm,
                                     char[] a,
                                     char[] b,
                                     int from,
                                     int to,
                                     boolean stable)
Sorts the specified pair of arrays lexicographically using indirect radix sort.

The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, Keith Bostic and M. Douglas McIlroy, “Engineering radix sort”, Computing Systems, 6(1), pages 5−27 (1993), and further improved using the digit-oracle idea described by Juha Kärkkäinen and Tommi Rantala in “Engineering radix sort for strings”, String Processing and Information Retrieval, 15th International Symposium, volume 5280 of Lecture Notes in Computer Science, pages 3−14, Springer (2008).

This method implement an indirect sort. The elements of perm (which must be exactly the numbers in the interval [0..perm.length)) will be permuted so that a[ perm[ i ] ] <= a[ perm[ i + 1 ] ].

This implementation is significantly faster than quicksort (unstable) or mergesort (stable) already at small sizes (say, more than 10000 elements), but it can only sort in ascending order. It will allocate a support array of bytes with the same number of elements as the array to be sorted, and, in the stable case, a further support array as large as perm (note that the stable version is slightly faster).

Parameters:
perm - a permutation array indexing a.
a - the array to be sorted.
b - the second array to be sorted.
from - the index of the first element of perm (inclusive) to be permuted.
to - the index of the last element of perm (exclusive) to be permuted.
stable - whether the sorting algorithm should be stable.

radixSort

public static void radixSort(char[][] a)
Sorts the specified array of arrays lexicographically using radix sort.

The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, Keith Bostic and M. Douglas McIlroy, “Engineering radix sort”, Computing Systems, 6(1), pages 5−27 (1993), and further improved using the digit-oracle idea described by Juha Kärkkäinen and Tommi Rantala in “Engineering radix sort for strings”, String Processing and Information Retrieval, 15th International Symposium, volume 5280 of Lecture Notes in Computer Science, pages 3−14, Springer (2008).

This method implements a lexicographical sorting of the provided arrays. Tuples of elements in the same position will be considered a single key, and permuted accordingly.

This implementation is significantly faster than quicksort already at small sizes (say, more than 10000 elements), but it can only sort in ascending order. It will allocate a support array of bytes with the same number of elements as the arrays to be sorted.

Parameters:
a - an array containing arrays of equal length to be sorted lexicographically in parallel.

radixSort

public static void radixSort(char[][] a,
                             int from,
                             int to)
Sorts the specified array of arrays lexicographically using radix sort.

The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, Keith Bostic and M. Douglas McIlroy, “Engineering radix sort”, Computing Systems, 6(1), pages 5−27 (1993), and further improved using the digit-oracle idea described by Juha Kärkkäinen and Tommi Rantala in “Engineering radix sort for strings”, String Processing and Information Retrieval, 15th International Symposium, volume 5280 of Lecture Notes in Computer Science, pages 3−14, Springer (2008).

This method implements a lexicographical sorting of the provided arrays. Tuples of elements in the same position will be considered a single key, and permuted accordingly.

This implementation is significantly faster than quicksort already at small sizes (say, more than 10000 elements), but it can only sort in ascending order. It will allocate a support array of bytes with the same number of elements as the arrays to be sorted.

Parameters:
a - an array containing arrays of equal length to be sorted lexicographically in parallel.
from - the index of the first element (inclusive) to be sorted.
to - the index of the last element (exclusive) to be sorted.

shuffle

public static char[] shuffle(char[] a,
                             int from,
                             int to,
                             Random random)
Shuffles the specified array fragment using the specified pseudorandom number generator.

Parameters:
a - the array to be shuffled.
from - the index of the first element (inclusive) to be shuffled.
to - the index of the last element (exclusive) to be shuffled.
random - a pseudorandom number generator (please use a XorShift* generator).
Returns:
a.

shuffle

public static char[] shuffle(char[] a,
                             Random random)
Shuffles the specified array using the specified pseudorandom number generator.

Parameters:
a - the array to be shuffled.
random - a pseudorandom number generator (please use a XorShift* generator).
Returns:
a.

reverse

public static char[] reverse(char[] a)
Reverses the order of the elements in the specified array.

Parameters:
a - the array to be reversed.
Returns:
a.