Class IntBigArrays


  • public final class IntBigArrays
    extends Object
    A class providing static methods and objects that do useful things with big arrays.

    In particular, the forceCapacity(), ensureCapacity(), grow(), trim() and setLength() methods allow to handle big arrays much like array lists.

    Note that BinIO and TextIO contain several methods that make it possible to load and save big 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:
    BigArrays
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int[][] DEFAULT_EMPTY_BIG_ARRAY
      A static, final, empty big array to be used as default big array in allocations.
      static int[][] EMPTY_BIG_ARRAY
      A static, final, empty big array.
      static Hash.Strategy HASH_STRATEGY
      A type-specific content-based hash strategy for big arrays.
    • Method Summary

      Modifier and Type Method Description
      static void add​(int[][] array, long index, int incr)
      Deprecated.
      Please use the version in BigArrays.
      static long binarySearch​(int[][] a, int key)
      Searches a big array for the specified value using the binary search algorithm.
      static long binarySearch​(int[][] a, int key, IntComparator c)
      Searches a big array for the specified value using the binary search algorithm and a specified comparator.
      static long binarySearch​(int[][] a, long from, long to, int key)
      Searches a range of the specified big array for the specified value using the binary search algorithm.
      static long binarySearch​(int[][] a, long from, long to, int key, IntComparator c)
      Searches a range of the specified big array for the specified value using the binary search algorithm and a specified comparator.
      static int[][] copy​(int[][] array)
      Deprecated.
      Please use the version in BigArrays.
      static void copy​(int[][] srcArray, long srcPos, int[][] destArray, long destPos, long length)
      Deprecated.
      Please use the version in BigArrays.
      static int[][] copy​(int[][] array, long offset, long length)
      Deprecated.
      Please use the version in BigArrays.
      static void copyFromBig​(int[][] srcArray, long srcPos, int[] destArray, int destPos, int length)
      Deprecated.
      Please use the version in BigArrays.
      static void copyToBig​(int[] srcArray, int srcPos, int[][] destArray, long destPos, long length)
      Deprecated.
      Please use the version in BigArrays.
      static void decr​(int[][] array, long index)
      Deprecated.
      Please use the version in BigArrays.
      static int[][] ensureCapacity​(int[][] array, long length)
      Deprecated.
      Please use the version in BigArrays.
      static int[][] ensureCapacity​(int[][] array, long length, long preserve)
      Deprecated.
      Please use the version in BigArrays.
      static void ensureFromTo​(int[][] a, long from, long to)
      Deprecated.
      Please use the version in BigArrays.
      static void ensureOffsetLength​(int[][] a, long offset, long length)
      Deprecated.
      Please use the version in BigArrays.
      static void ensureSameLength​(int[][] a, int[][] b)
      Deprecated.
      Please use the version in BigArrays.
      static boolean equals​(int[][] a1, int[][] a2)
      Deprecated.
      Please use the version in BigArrays.
      static void fill​(int[][] array, int value)
      Deprecated.
      Please use the version in BigArrays.
      static void fill​(int[][] array, long from, long to, int value)
      Deprecated.
      Please use the version in BigArrays.
      static int[][] forceCapacity​(int[][] array, long length, long preserve)
      Deprecated.
      Please use the version in BigArrays.
      static int get​(int[][] array, long index)
      Deprecated.
      Please use the version in BigArrays.
      static int[][] grow​(int[][] array, long length)
      Deprecated.
      Please use the version in BigArrays.
      static int[][] grow​(int[][] array, long length, long preserve)
      Deprecated.
      Please use the version in BigArrays.
      static void incr​(int[][] array, long index)
      Deprecated.
      Please use the version in BigArrays.
      static long length​(int[][] array)
      Deprecated.
      Please use the version in BigArrays.
      static void mul​(int[][] array, long index, int factor)
      Deprecated.
      Please use the version in BigArrays.
      static int[][] newBigArray​(long length)
      Creates a new big array.
      static void quickSort​(int[][] x)
      Sorts the specified big array according to the natural ascending order using quicksort.
      static void quickSort​(int[][] x, long from, long to)
      Sorts the specified range of elements according to the natural ascending order using quicksort.
      static void quickSort​(int[][] x, long from, long to, IntComparator comp)
      Sorts the specified range of elements according to the order induced by the specified comparator using quicksort.
      static void quickSort​(int[][] x, IntComparator comp)
      Sorts the specified big array according to the order induced by the specified comparator using quicksort.
      static void radixSort​(int[][] a)
      Sorts the specified big array using radix sort.
      static void radixSort​(int[][] a, int[][] b)
      Sorts the specified pair of big arrays lexicographically using radix sort.
      static void radixSort​(int[][] a, int[][] b, long from, long to)
      Sorts the specified pair of big arrays lexicographically using radix sort.
      static void radixSort​(int[][] a, long from, long to)
      Sorts the specified big array using radix sort.
      static void radixSortIndirect​(long[][] perm, int[][] a, int[][] b, boolean stable)
      Sorts the specified pair of arrays lexicographically using indirect radix sort.
      static void radixSortIndirect​(long[][] perm, int[][] a, int[][] b, long from, long to, boolean stable)
      Sorts the specified pair of arrays lexicographically using indirect radix sort.
      static void set​(int[][] array, long index, int value)
      Deprecated.
      Please use the version in BigArrays.
      static int[][] setLength​(int[][] array, long length)
      Deprecated.
      Please use the version in BigArrays.
      static int[][] shuffle​(int[][] a, long from, long to, Random random)
      Shuffles the specified big array fragment using the specified pseudorandom number generator.
      static int[][] shuffle​(int[][] a, Random random)
      Shuffles the specified big array using the specified pseudorandom number generator.
      static void swap​(int[][] array, long first, long second)
      Deprecated.
      Please use the version in BigArrays.
      static String toString​(int[][] a)
      Deprecated.
      static int[][] trim​(int[][] array, long length)
      Deprecated.
      Please use the version in BigArrays.
      static int[][] wrap​(int[] array)
      Deprecated.
      Please use the version in BigArrays.
    • Field Detail

      • EMPTY_BIG_ARRAY

        public static final int[][] EMPTY_BIG_ARRAY
        A static, final, empty big array.
      • DEFAULT_EMPTY_BIG_ARRAY

        public static final int[][] DEFAULT_EMPTY_BIG_ARRAY
        A static, final, empty big array to be used as default big array in allocations. An object distinct from EMPTY_BIG_ARRAY makes it possible to have different behaviors depending on whether the user required an empty allocation, or we are just lazily delaying allocation.
        See Also:
        ArrayList
      • HASH_STRATEGY

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

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

    • Method Detail

      • get

        @Deprecated
        public static int get​(int[][] array,
                              long index)
        Deprecated.
        Please use the version in BigArrays.
        Returns the element of the given big array of specified index.
        Parameters:
        array - a big array.
        index - a position in the big array.
        Returns:
        the element of the big array at the specified position.
      • set

        @Deprecated
        public static void set​(int[][] array,
                               long index,
                               int value)
        Deprecated.
        Please use the version in BigArrays.
        Sets the element of the given big array of specified index.
        Parameters:
        array - a big array.
        index - a position in the big array.
        value - the new value for the array element at the specified position.
      • swap

        @Deprecated
        public static void swap​(int[][] array,
                                long first,
                                long second)
        Deprecated.
        Please use the version in BigArrays.
        Swaps the element of the given big array of specified indices.
        Parameters:
        array - a big array.
        first - a position in the big array.
        second - a position in the big array.
      • add

        @Deprecated
        public static void add​(int[][] array,
                               long index,
                               int incr)
        Deprecated.
        Please use the version in BigArrays.
        Adds the specified increment the element of the given big array of specified index.
        Parameters:
        array - a big array.
        index - a position in the big array.
        incr - the increment
      • mul

        @Deprecated
        public static void mul​(int[][] array,
                               long index,
                               int factor)
        Deprecated.
        Please use the version in BigArrays.
        Multiplies by the specified factor the element of the given big array of specified index.
        Parameters:
        array - a big array.
        index - a position in the big array.
        factor - the factor
      • incr

        @Deprecated
        public static void incr​(int[][] array,
                                long index)
        Deprecated.
        Please use the version in BigArrays.
        Increments the element of the given big array of specified index.
        Parameters:
        array - a big array.
        index - a position in the big array.
      • decr

        @Deprecated
        public static void decr​(int[][] array,
                                long index)
        Deprecated.
        Please use the version in BigArrays.
        Decrements the element of the given big array of specified index.
        Parameters:
        array - a big array.
        index - a position in the big array.
      • length

        @Deprecated
        public static long length​(int[][] array)
        Deprecated.
        Please use the version in BigArrays.
        Returns the length of the given big array.
        Parameters:
        array - a big array.
        Returns:
        the length of the given big array.
      • copy

        @Deprecated
        public static void copy​(int[][] srcArray,
                                long srcPos,
                                int[][] destArray,
                                long destPos,
                                long length)
        Deprecated.
        Please use the version in BigArrays.
        Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination big array. Handles correctly overlapping regions of the same big array.
        Parameters:
        srcArray - the source big array.
        srcPos - the starting position in the source big array.
        destArray - the destination big array.
        destPos - the starting position in the destination data.
        length - the number of elements to be copied.
      • copyFromBig

        @Deprecated
        public static void copyFromBig​(int[][] srcArray,
                                       long srcPos,
                                       int[] destArray,
                                       int destPos,
                                       int length)
        Deprecated.
        Please use the version in BigArrays.
        Copies a big array from the specified source big array, beginning at the specified position, to the specified position of the destination array.
        Parameters:
        srcArray - the source big array.
        srcPos - the starting position in the source big array.
        destArray - the destination array.
        destPos - the starting position in the destination data.
        length - the number of elements to be copied.
      • copyToBig

        @Deprecated
        public static void copyToBig​(int[] srcArray,
                                     int srcPos,
                                     int[][] destArray,
                                     long destPos,
                                     long length)
        Deprecated.
        Please use the version in BigArrays.
        Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination big array.
        Parameters:
        srcArray - the source array.
        srcPos - the starting position in the source array.
        destArray - the destination big array.
        destPos - the starting position in the destination data.
        length - the number of elements to be copied.
      • newBigArray

        public static int[][] newBigArray​(long length)
        Creates a new big array.
        Parameters:
        length - the length of the new big array.
        Returns:
        a new big array of given length.
      • wrap

        @Deprecated
        public static int[][] wrap​(int[] array)
        Deprecated.
        Please use the version in BigArrays.
        Turns a standard array into a big array.

        Note that the returned big array might contain as a segment the original array.

        Parameters:
        array - an array.
        Returns:
        a new big array with the same length and content of array.
      • ensureCapacity

        @Deprecated
        public static int[][] ensureCapacity​(int[][] array,
                                             long length)
        Deprecated.
        Please use the version in BigArrays.
        Ensures that a big array can contain the given number of entries.

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

        Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.

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

        @Deprecated
        public static int[][] forceCapacity​(int[][] array,
                                            long length,
                                            long preserve)
        Deprecated.
        Please use the version in BigArrays.
        Forces a big array to contain the given number of entries, preserving just a part of the big array.

        Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.

        Parameters:
        array - a big array.
        length - the new minimum length for this big array.
        preserve - the number of elements of the big array that must be preserved in case a new allocation is necessary.
        Returns:
        a big array with length entries whose first preserve entries are the same as those of array.
      • ensureCapacity

        @Deprecated
        public static int[][] ensureCapacity​(int[][] array,
                                             long length,
                                             long preserve)
        Deprecated.
        Please use the version in BigArrays.
        Ensures that a big array can contain the given number of entries, preserving just a part of the big array.

        Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.

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

        @Deprecated
        public static int[][] grow​(int[][] array,
                                   long length)
        Deprecated.
        Please use the version in BigArrays.
        Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length.

        If you want complete control on the big array growth, you should probably use ensureCapacity() instead.

        Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.

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

        @Deprecated
        public static int[][] grow​(int[][] array,
                                   long length,
                                   long preserve)
        Deprecated.
        Please use the version in BigArrays.
        Grows the given big array to the maximum between the given length and the current length increased by 50%, provided that the given length is larger than the current length, preserving just a part of the big array.

        If you want complete control on the big array growth, you should probably use ensureCapacity() instead.

        Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.

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

        @Deprecated
        public static int[][] trim​(int[][] array,
                                   long length)
        Deprecated.
        Please use the version in BigArrays.
        Trims the given big array to the given length.

        Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.

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

        @Deprecated
        public static int[][] setLength​(int[][] array,
                                        long length)
        Deprecated.
        Please use the version in BigArrays.
        Sets the length of the given big array.

        Warning: the returned array might use part of the segments of the original array, which must be considered read-only after calling this method.

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

        @Deprecated
        public static int[][] copy​(int[][] array,
                                   long offset,
                                   long length)
        Deprecated.
        Please use the version in BigArrays.
        Returns a copy of a portion of a big array.
        Parameters:
        array - a big array.
        offset - the first element to copy.
        length - the number of elements to copy.
        Returns:
        a new big array containing length elements of array starting at offset.
      • copy

        @Deprecated
        public static int[][] copy​(int[][] array)
        Deprecated.
        Please use the version in BigArrays.
        Returns a copy of a big array.
        Parameters:
        array - a big array.
        Returns:
        a copy of array.
      • fill

        @Deprecated
        public static void fill​(int[][] array,
                                int value)
        Deprecated.
        Please use the version in BigArrays.
        Fills the given big array with the given value.

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

        Parameters:
        array - a big array.
        value - the new value for all elements of the big array.
      • fill

        @Deprecated
        public static void fill​(int[][] array,
                                long from,
                                long to,
                                int value)
        Deprecated.
        Please use the version in BigArrays.
        Fills a portion of the given big 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 - a big array.
        from - the starting index of the portion to fill.
        to - the end index of the portion to fill.
        value - the new value for all elements of the specified portion of the big array.
      • equals

        @Deprecated
        public static boolean equals​(int[][] a1,
                                     int[][] a2)
        Deprecated.
        Please use the version in BigArrays.
        Returns true if the two big arrays are elementwise equal.

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

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

        @Deprecated
        public static void ensureFromTo​(int[][] a,
                                        long from,
                                        long to)
        Deprecated.
        Please use the version in BigArrays.
        Ensures that a range given by its first (inclusive) and last (exclusive) elements fits a big array.

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

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

        @Deprecated
        public static void ensureOffsetLength​(int[][] a,
                                              long offset,
                                              long length)
        Deprecated.
        Please use the version in BigArrays.
        Ensures that a range given by an offset and a length fits a big array.

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

        Parameters:
        a - a big 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 big array length.
      • ensureSameLength

        @Deprecated
        public static void ensureSameLength​(int[][] a,
                                            int[][] b)
        Deprecated.
        Please use the version in BigArrays.
        Ensures that two big arrays are of the same length.
        Parameters:
        a - a big array.
        b - another big array.
        Throws:
        IllegalArgumentException - if the two argument arrays are not of the same length.
      • quickSort

        public static void quickSort​(int[][] x,
                                     long from,
                                     long to,
                                     IntComparator 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 big 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​(int[][] x,
                                     IntComparator comp)
        Sorts the specified big 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 big array to be sorted.
        comp - the comparator to determine the sorting order.
      • quickSort

        public static void quickSort​(int[][] x,
                                     long from,
                                     long 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 big 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​(int[][] x)
        Sorts the specified big 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 big array to be sorted.
      • binarySearch

        public static long binarySearch​(int[][] a,
                                        long from,
                                        long to,
                                        int key)
        Searches a range of the specified big 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 big 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 big array; otherwise, (-(insertion point) - 1). The insertion point is defined as the the point at which the value would be inserted into the big array: the index of the first element greater than the key, or the length of the big array, if all elements in the big 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 long binarySearch​(int[][] a,
                                        int key)
        Searches a big 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 big array to be searched.
        key - the value to be searched for.
        Returns:
        index of the search key, if it is contained in the big array; otherwise, (-(insertion point) - 1). The insertion point is defined as the the point at which the value would be inserted into the big array: the index of the first element greater than the key, or the length of the big array, if all elements in the big 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 long binarySearch​(int[][] a,
                                        long from,
                                        long to,
                                        int key,
                                        IntComparator c)
        Searches a range of the specified big 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 big 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 big array; otherwise, (-(insertion point) - 1). The insertion point is defined as the the point at which the value would be inserted into the big array: the index of the first element greater than the key, or the length of the big array, if all elements in the big 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 long binarySearch​(int[][] a,
                                        int key,
                                        IntComparator c)
        Searches a big 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 big 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 big array; otherwise, (-(insertion point) - 1). The insertion point is defined as the the point at which the value would be inserted into the big array: the index of the first element greater than the key, or the length of the big array, if all elements in the big 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​(int[][] a)
        Sorts the specified big 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 big array to be sorted.
      • radixSort

        public static void radixSort​(int[][] a,
                                     long from,
                                     long to)
        Sorts the specified big 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 big 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.
      • radixSort

        public static void radixSort​(int[][] a,
                                     int[][] b)
        Sorts the specified pair of big 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 big array to be sorted.
        b - the second big array to be sorted.
      • radixSort

        public static void radixSort​(int[][] a,
                                     int[][] b,
                                     long from,
                                     long to)
        Sorts the specified pair of big 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 big array to be sorted.
        b - the second big 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​(long[][] perm,
                                             int[][] a,
                                             int[][] 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).

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

        This implementation will allocate, 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​(long[][] perm,
                                             int[][] a,
                                             int[][] b,
                                             long from,
                                             long 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).

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

        This implementation will allocate, 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.
      • shuffle

        public static int[][] shuffle​(int[][] a,
                                      long from,
                                      long to,
                                      Random random)
        Shuffles the specified big array fragment using the specified pseudorandom number generator.
        Parameters:
        a - the big 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.
        Returns:
        a.
      • shuffle

        public static int[][] shuffle​(int[][] a,
                                      Random random)
        Shuffles the specified big array using the specified pseudorandom number generator.
        Parameters:
        a - the big array to be shuffled.
        random - a pseudorandom number generator.
        Returns:
        a.