Documentation of 'cc.redberry.core.utils.ArraysUtils' Java class
ArraysUtils
cc.redberry.core.utils

Class ArraysUtils



  • public final class ArraysUtils
    extends java.lang.Object
    This class contains additional methods for manipulating arrays (such as sorting and searching). For all quick sort methods the base code was taken from jdk6 Arrays class.
    See Also:
    Arrays
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static java.util.Comparator<java.lang.Object> HASH_COMPARATOR 
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static int[] addAll(int[]... arrays) 
      static int[] addAll(int[] array1, int... array2) 
      static <T> T[] addAll(T[] array1, T... array2)
      This code is taken from Apache Commons Lang ArrayUtils.
      static Tensor[] addAll(Tensor[] array1, Tensor... array2) 
      static void arraycopy(IntArray source, int srcPos, int[] dest, int destPos, int length) 
      static <T extends java.lang.Comparable<? super T>>
      int[]
      bijection(T[] from, T[] to)
      Creates a bijective mapping between two arrays and returns the resulting bijection as array.
      static <T> int[] bijection(T[] from, T[] to, java.util.Comparator<? super T> comparator)
      This method is similar to bijection(Comparable[], Comparable[]) }, but uses specified comparator.
      static int binarySearch(IntArray array, int key)
      Searches a range of the specified array of ints for the specified value using the binary search algorithm.
      static int binarySearch(IntArrayList list, int key)
      Searches a range of the specified array of ints for the specified value using the binary search algorithm.
      static int binarySearch1(int[] a, int key)
      This is the same method to Arrays.binarySearch(int[], int).
      static int binarySearch1(int[] a, int fromIndex, int toIndex, int key)
      This is the same method to Arrays.binarySearch(int[], int, int, int).
      static int[] byte2int(byte[] a) 
      static short[] byte2short(byte[] a) 
      static int commutativeHashCode(java.lang.Object[] objects)
      Returns xor of objects hashes via HashFunctions.JenkinWang32shift(int)
      static int commutativeHashCode(java.lang.Object[] objects, int from, int to)
      Returns xor of objects hashes spreaded by HashFunctions.JenkinWang32shift(int)
      static int[][] deepClone(int[][] input) 
      static void fill(IntArrayList list, int value)
      Assigns the specified int value to each element of the specified list of ints.
      static void fill(IntArrayList list, int fromIndex, int toIndex, int value)
      Assigns the specified int value to each element of the specified range of the specified list.
      static int[] getSeriesFrom0(int size) 
      static void insertionSort(int[] target, int[] coSort)
      Sorts the specified array of ints into ascending order using insertion sort algorithm and simultaneously permutes the coSort ints array in the same way as the target array.
      static void insertionSort(int[] target, int fromIndex, int toIndex, int[] coSort)
      Sorts the specified array of ints into ascending order using insertion sort algorithm and simultaneously permutes the coSort ints array in the same way as the target array.
      static void insertionSort(int[] target, int fromIndex, int toIndex, long[] coSort)
      Sorts the specified array of ints into ascending order using insertion sort algorithm and simultaneously permutes the coSort ints array in the same way as the target array.
      static void insertionSort(int[] target, long[] coSort)
      Sorts the specified array of ints into ascending order using insertion sort algorithm and simultaneously permutes the coSort longs array in the same way as the specified target array.
      static <T extends java.lang.Comparable<T>>
      void
      insertionSort(T[] target, int fromIndex, int toIndex, java.lang.Object[] coSort)
      Sorts the specified target array of objects into ascending order, according to the natural ordering of its elements using insertion sort algorithm and simultaneously permutes the coSort objects array in the same way then specified target array.
      static <T extends java.lang.Comparable<T>>
      void
      insertionSort(T[] target, java.lang.Object[] coSort)
      Sorts the specified target array of objects into ascending order, according to the natural ordering of its elements using insertion sort algorithm and simultaneously permutes the coSort objects array in the same way then specified target array.
      static byte[] int2byte(int[] a) 
      static short[] int2short(int[] a) 
      static int max(int[] array) 
      static void quickSort(int[] target, int[] coSort)
      Sorts the specified target array of ints into ascending numerical order and simultaneously permutes the coSort ints array in the same way as the target array.
      static void quickSort(int[] target, int[] cosort, IntComparator comparator)
      Sorts the specified target array of ints according to IntComparator and simultaneously permutes the coSort Objects array in the same way as the target array.
      static void quickSort(int[] target, IntComparator comparator)
      Sorts the specified range of the specified target array of ints into order specified by IntComparator using quicksort.
      static void quickSort(int[] target, int fromIndex, int toIndex, int[] coSort)
      Sorts the specified range of the specified target array of ints into ascending numerical order and simultaneously permutes the coSort ints array in the same way as the target array.
      static void quickSort(int[] target, int fromIndex, int toIndex, int[] cosort, IntComparator comparator)
      Sorts the specified range of the specified target array of ints according to IntComparator and simultaneously permutes the coSort Objects array in the same way as the target array.
      static void quickSort(int[] target, int fromIndex, int toIndex, IntComparator comparator)
      Sorts the specified range of the specified target array of ints into order specified by IntComparator using quicksort.
      static void quickSort(int[] target, int fromIndex, int toIndex, long[] coSort)
      Sorts the specified range of the specified target array of ints into ascending numerical order and simultaneously permutes the coSort longs array in the same way as the target array.
      static void quickSort(int[] target, int fromIndex, int toIndex, java.lang.Object[] coSort)
      Sorts the specified range of the specified target array of ints into ascending numerical order and simultaneously permutes the coSort Objects array in the same way as the target array.
      static void quickSort(int[] target, long[] coSort)
      Sorts the specified target array of ints into ascending numerical order and simultaneously permutes the coSort longs array in the same way as the target array.
      static void quickSort(int[] target, java.lang.Object[] coSort)
      Sorts the specified target array of ints into ascending numerical order and simultaneously permutes the coSort Objects array in the same way as the target array.
      static void quickSort(short[] target, int[] coSort)
      Sorts the specified target array of shorts into ascending numerical order and simultaneously permutes the coSort ints array in the same way as the target array.
      static void quickSort(short[] target, int fromIndex, int toIndex, int[] coSort)
      Sorts the specified range of the specified target array of ints into ascending numerical order and simultaneously permutes the coSort ints array in the same way as the target array.
      static <T extends java.lang.Comparable<T>>
      void
      quickSort(T[] target, int[] coSort)
      Sorts the specified target array of objects into ascending order, according to the natural ordering of its elements and simultaneously permutes the coSort objects array in the same way then specified target array.
      static <T extends java.lang.Comparable<T>>
      void
      quickSort(T[] target, int fromIndex, int toIndex, int[] coSort)
      Sorts the specified target array of objects into ascending order, according to the natural ordering of its elements and simultaneously permutes the coSort objects array in the same way then specified target array.
      static <T extends java.lang.Comparable<T>>
      void
      quickSort(T[] target, int fromIndex, int toIndex, java.lang.Object[] coSort)
      Sorts the specified target array of objects into ascending order, according to the natural ordering of its elements and simultaneously permutes the coSort objects array in the same way then specified target array.
      static <T extends java.lang.Comparable<T>>
      void
      quickSort(T[] target, java.lang.Object[] coSort)
      Sorts the specified target array of objects into ascending order, according to the natural ordering of its elements and simultaneously permutes the coSort objects array in the same way then specified target array.
      static void quickSort1(int[] target, int fromIndex, int length, int[] coSort)
      This method is the same as quickSort(int[], int, int, int[]), but without range checking and toIndex -> length (see params).
      static void quickSort1(int[] target, int fromIndex, int length, IntComparator comparator)
      Sorts the specified range of the specified target array of ints into order specified by IntComparator using quicksort.
      static void quickSort1(int[] target, int fromIndex, int length, long[] coSort)
      This method is the same as ) , but without range checking.
      static void quickSort1(int[] target, int fromIndex, int length, java.lang.Object[] coSort)
      This method is the same as ) , but without range checking.
      static void quickSort1(short[] target, int fromIndex, int length, int[] coSort)
      This method is the same as quickSort(int[], int, int, int[]), but without range checking and toIndex -> length (see params).
      static <T extends java.lang.Comparable<T>>
      void
      quickSort1(T[] target, int fromIndex, int length, int[] coSort)
      This method is the same as quickSort(Comparable[], int, int, Object[]), but without range checking.
      static <T extends java.lang.Comparable<T>>
      void
      quickSort1(T[] target, int fromIndex, int length, java.lang.Object[] coSort)
      This method is the same as quickSort(Comparable[], int, int, Object[]), but without range checking.
      static int[] quickSortP(int[] target)
      Sorts the specified array and returns the resulting permutation
      static int[] quickSortP(short[] target) 
      static int[] remove(int[] array, int[] positions)
      Removes elements at specified positions in specified array.
      static <T> T[] remove(T[] array, int i) 
      static <T> T[] remove(T[] array, int[] positions)
      Removes elements at specified positions in specified array.
      static Tensor[] remove(Tensor[] array, int i) 
      static Tensor[] remove(Tensor[] array, int[] positions)
      Removes elements at specified positions in specified array.
      static <T> T[] select(T[] array, int[] positions)
      Selects elements from specified array at specified positions.
      static int[] short2int(short[] a) 
      static void stableSort(int[] target, int[] cosort)
      Sorts the specified array of ints into ascending order using stable sort algorithm and simultaneously permutes the coSort ints array in the same way as the target array.
      static int sum(int[] array) 
      static void swap(int[] x, int a, int b)
      Swaps x[a] with x[b].
      static void swap(java.lang.Object[] x, int a, int b)
      Swaps x[a] with x[b].
      static void timSort(int[] target, int[] coSort)
      Sorts the specified array of ints into ascending order using TimSort algorithm and simultaneously permutes the coSort ints array in the same way as the target array.
      static int[] toArray(java.util.Set<java.lang.Integer> set)
      Converts Set<Integer> to int[]
      static java.lang.String toString(int[] a, ToStringConverter<java.lang.Integer> format) 
      static <T> java.lang.String toString(T[] a, ToStringConverter<T> format) 
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • HASH_COMPARATOR

        public static final java.util.Comparator<java.lang.Object> HASH_COMPARATOR
    • Method Detail

      • arraycopy

        public static void arraycopy(IntArray source,
                                     int srcPos,
                                     int[] dest,
                                     int destPos,
                                     int length)
      • short2int

        public static int[] short2int(short[] a)
      • int2short

        public static short[] int2short(int[] a)
      • byte2int

        public static int[] byte2int(byte[] a)
      • byte2short

        public static short[] byte2short(byte[] a)
      • int2byte

        public static byte[] int2byte(int[] a)
      • max

        public static int max(int[] array)
      • getSeriesFrom0

        public static int[] getSeriesFrom0(int size)
      • deepClone

        public static int[][] deepClone(int[][] input)
      • sum

        public static int sum(int[] array)
      • bijection

        public static <T> int[] bijection(T[] from,
                                          T[] to,
                                          java.util.Comparator<? super T> comparator)
        This method is similar to bijection(Comparable[], Comparable[]) }, but uses specified comparator.
        Parameters:
        from - from array
        to - to array
        comparator - comparator
        Returns:
        a bijective mapping from from-array to to-array and null if no mapping exist
      • bijection

        public static <T extends java.lang.Comparable<? super T>> int[] bijection(T[] from,
                                                                                  T[] to)
        Creates a bijective mapping between two arrays and returns the resulting bijection as array. Method returns null, if no mapping found.

        Example:

              Integer from[] = {1,2,1,4};
              Integer to[] = {2,4,1,1};
              int[] bijection = bijection(from,to);
         

        The resulting bijection will be [2, 0, 3, 1]

        Parameters:
        from - from array
        to - to array
        Returns:
        a bijective mapping from from-array to to-array and null if no mapping exist
      • addAll

        public static int[] addAll(int[] array1,
                                   int... array2)
      • addAll

        public static int[] addAll(int[]... arrays)
      • remove

        public static Tensor[] remove(Tensor[] array,
                                      int i)
      • remove

        public static <T> T[] remove(T[] array,
                                     int i)
      • addAll

        @SafeVarargs
        public static <T> T[] addAll(T[] array1,
                                                  T... array2)
        This code is taken from Apache Commons Lang ArrayUtils.

        Adds all the elements of the given arrays into a new array.

        The new array contains all of the element of array1 followed by all of the elements array2. When an array is returned, it is always a new array.

         ArrayUtils.addAll(null, null)     = null
         ArrayUtils.addAll(array1, null)   = cloned copy of array1
         ArrayUtils.addAll(null, array2)   = cloned copy of array2
         ArrayUtils.addAll([], [])         = []
         ArrayUtils.addAll([null], [null]) = [null, null]
         ArrayUtils.addAll(["a", "b", "c"], ["1", "2", "3"]) = ["a", "b", "c", "1", "2", "3"]
         
        Type Parameters:
        T - the component type of the array
        Parameters:
        array1 - the first array whose elements are added to the new array, may be null
        array2 - the second array whose elements are added to the new array, may be null
        Returns:
        The new array, null if both arrays are null. The type of the new array is the type of the first array, unless the first array is null, in which case the type is the same as the second array.
        Throws:
        java.lang.IllegalArgumentException - if the array types are incompatible
        Since:
        2.1
      • remove

        public static <T> T[] remove(T[] array,
                                     int[] positions)
        Removes elements at specified positions in specified array. This method preserve the relative order of elements in specified array.
        Type Parameters:
        T - generic type
        Parameters:
        array - array of elements
        positions - positions of elements that should be removed
        Returns:
        new array with removed elements at specified positions
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - if some position larger then array length
      • remove

        public static Tensor[] remove(Tensor[] array,
                                      int[] positions)
        Removes elements at specified positions in specified array. This method preserve the relative order of elements in specified array.
        Parameters:
        array - array of elements
        positions - positions of elements that should be removed
        Returns:
        new array with removed elements at specified positions
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - if some position larger then array length
      • remove

        public static int[] remove(int[] array,
                                   int[] positions)
        Removes elements at specified positions in specified array. This method preserve the relative order of elements in specified array.
        Parameters:
        array - array of elements
        positions - positions of elements that should be removed
        Returns:
        new array with removed elements at specified positions
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - if some position larger then array length
      • select

        public static <T> T[] select(T[] array,
                                     int[] positions)
        Selects elements from specified array at specified positions. The resulting array preserves the relative order of elements in specified array.
        Type Parameters:
        T - generic type
        Parameters:
        array - array of elements
        positions - of elements that should be picked out
        Returns:
        the array of elements that picked out from specified positions in specified array
      • toArray

        public static int[] toArray(java.util.Set<java.lang.Integer> set)
        Converts Set<Integer> to int[]
        Parameters:
        set - a Set of Integer
        Returns:
        int[]
      • fill

        public static void fill(IntArrayList list,
                                int fromIndex,
                                int toIndex,
                                int value)
        Assigns the specified int value to each element of the specified range of the specified list. The range to be filled extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be filled is empty.)
        Parameters:
        list - the list to be filled
        fromIndex - the index of the first element (inclusive) to be filled with the specified value
        toIndex - the index of the last element (exclusive) to be filled with the specified value
        value - the value to be stored in all elements of the array
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.ArrayIndexOutOfBoundsException - if fromIndex < 0 or toIndex > a.length
      • fill

        public static void fill(IntArrayList list,
                                int value)
        Assigns the specified int value to each element of the specified list of ints.
        Parameters:
        list - the array to be filled
        value - the value to be stored in all elements of the array
      • binarySearch

        public static int binarySearch(IntArrayList list,
                                       int key)
        Searches a range of the specified array of ints for the specified value using the binary search algorithm. The range must be sorted (as by the IntArrayList.sort() method) 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:
        list - the list to be searched
        key - the value to be searched for
        Returns:
        index of the search key, if it is contained in the array within the specified range; otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element in the range greater than the key, or toIndex if all elements in the range 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(int[], int)
      • binarySearch

        public static int binarySearch(IntArray array,
                                       int key)
        Searches a range of the specified array of ints for the specified value using the binary search algorithm. The range must be sorted (as by the IntArrayList.sort() method) 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:
        array - the list to be searched
        key - the value to be searched for
        Returns:
        index of the search key, if it is contained in the array within the specified range; otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element in the range greater than the key, or toIndex if all elements in the range 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(int[], int)
      • binarySearch1

        public static int binarySearch1(int[] a,
                                        int key)
        This is the same method to Arrays.binarySearch(int[], int). The differs is in the returned value. If key not found, this method returns the position of the first element, witch is closest to key (i.e. if Arrays.binarySearch returns -low-1, this method returns low).
        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. The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element greater than the key, or a.length if all elements in the array are less than the specified key.
      • binarySearch1

        public static int binarySearch1(int[] a,
                                        int fromIndex,
                                        int toIndex,
                                        int key)
        This is the same method to Arrays.binarySearch(int[], int, int, int). The differs is in the returned value. If key not found, this method returns the position of the first element, witch is closest to key (i.e. if Arrays.binarySearch returns -low-1, this method returns low).
        Parameters:
        a - the array to be searched
        key - the value to be searched for
        fromIndex - the index of the first element (inclusive) to be searched
        toIndex - the index of the last element (exclusive) to be searched
        Returns:
        index of the search key, if it is contained in the array; otherwise, insertion point. The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element greater than the key, or toIndex if all elements in the array are less than the specified key.
      • commutativeHashCode

        public static int commutativeHashCode(java.lang.Object[] objects)
        Returns xor of objects hashes via HashFunctions.JenkinWang32shift(int)
        Parameters:
        objects - array
        Returns:
        commutative hash
      • commutativeHashCode

        public static int commutativeHashCode(java.lang.Object[] objects,
                                              int from,
                                              int to)
        Returns xor of objects hashes spreaded by HashFunctions.JenkinWang32shift(int)
        Parameters:
        objects - array
        Returns:
        commutative hash
      • insertionSort

        public static void insertionSort(int[] target,
                                         int[] coSort)
        Sorts the specified array of ints into ascending order using insertion sort algorithm and simultaneously permutes the coSort ints array in the same way as the target array. This sort guarantee O(n^2) performance in the worst case and O(n) in the best case (nearly sorted input).

        This sort is the best choice for small arrays with elements number < 100.

        This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort; adaptive: performance adapts to the initial order of elements and in-place: requires constant amount of additional space.

        Parameters:
        target - the array to be sorted
        coSort - the array which will be permuted in the same way as the target array during sorting procedure
        Throws:
        java.lang.IllegalArgumentException - if coSort length less then target length.
      • insertionSort

        public static void insertionSort(int[] target,
                                         int fromIndex,
                                         int toIndex,
                                         int[] coSort)
        Sorts the specified array of ints into ascending order using insertion sort algorithm and simultaneously permutes the coSort ints array in the same way as the target array. This sort guarantee O(n^2) performance in the worst case and O(n) in the best case (nearly sorted input). The range to be sorted extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be sorted is empty.)

        This sort is the best choice for small arrays with elements number < 100.

        This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort; adaptive: performance adapts to the initial order of elements and in-place: requires constant amount of additional space.

        Parameters:
        target - the array to be sorted
        fromIndex - the index of the first element (inclusive) to be sorted
        toIndex - the index of the last element (exclusive) to be sorted
        coSort - the array which will be permuted in the same way as the target array, during sorting procedure
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.ArrayIndexOutOfBoundsException - if fromIndex < 0 or toIndex > target.length or toIndex > coSort.length
      • insertionSort

        public static void insertionSort(int[] target,
                                         long[] coSort)
        Sorts the specified array of ints into ascending order using insertion sort algorithm and simultaneously permutes the coSort longs array in the same way as the specified target array. This sort guarantee O(n^2) performance in the worst case and O(n) in the best case (nearly sorted input).

        This sort is the best choice for small arrays with elements number < 100.

        This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort; adaptive: performance adapts to the initial order of elements and in-place: requires constant amount of additional space.

        Parameters:
        target - the array to be sorted
        coSort - the array which will be permuted in the same way as the target array during sorting procedure
        Throws:
        java.lang.IllegalArgumentException - if coSort length less then target length.
      • insertionSort

        public static void insertionSort(int[] target,
                                         int fromIndex,
                                         int toIndex,
                                         long[] coSort)
        Sorts the specified array of ints into ascending order using insertion sort algorithm and simultaneously permutes the coSort ints array in the same way as the target array. This sort guarantee O(n^2) performance in the worst case and O(n) in the best case (nearly sorted input). The range to be sorted extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be sorted is empty.)

        This sort is the best choice for small arrays with elements number < 100.

        This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort; adaptive: performance adapts to the initial order of elements and in-place: requires constant amount of additional space.

        Parameters:
        target - the array to be sorted
        fromIndex - the index of the first element (inclusive) to be sorted
        toIndex - the index of the last element (exclusive) to be sorted
        coSort - the array which will be permuted in the same way as the specified target array, during sorting procedure
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.ArrayIndexOutOfBoundsException - if fromIndex < 0 or toIndex > target.length or toIndex > coSort.length
      • insertionSort

        public static <T extends java.lang.Comparable<T>> void insertionSort(T[] target,
                                                                             java.lang.Object[] coSort)
        Sorts the specified target array of objects into ascending order, according to the natural ordering of its elements using insertion sort algorithm and simultaneously permutes the coSort objects array in the same way then specified target array. This sort guarantee O(n^2) performance in the worst case and O(n) in the best case (nearly sorted input).

        This sort is the best choice for small arrays with elements number < 100.

        This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort; adaptive: performance adapts to the initial order of elements and in-place: requires constant amount of additional space.

        Parameters:
        target - the array to be sorted
        coSort - the array which will be permuted in the same way as the target array during sorting procedure
        Throws:
        java.lang.IllegalArgumentException - if coSort length less then target length.
      • insertionSort

        public static <T extends java.lang.Comparable<T>> void insertionSort(T[] target,
                                                                             int fromIndex,
                                                                             int toIndex,
                                                                             java.lang.Object[] coSort)
        Sorts the specified target array of objects into ascending order, according to the natural ordering of its elements using insertion sort algorithm and simultaneously permutes the coSort objects array in the same way then specified target array. This sort guarantee O(n^2) performance in the worst case and O(n) in the best case (nearly sorted input). The range to be sorted extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be sorted is empty.)

        This sort is the best choice for small arrays with elements number < 100.

        This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort; adaptive: performance adapts to the initial order of elements and in-place: requires constant amount of additional space.

        Parameters:
        target - the array to be sorted
        fromIndex - the index of the first element (inclusive) to be sorted
        toIndex - the index of the last element (exclusive) to be sorted
        coSort - the array which will be permuted in the same way as the target array, during sorting procedure
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.ArrayIndexOutOfBoundsException - if fromIndex < 0 or toIndex > target.length or toIndex > coSort.length
      • timSort

        public static void timSort(int[] target,
                                   int[] coSort)
        Sorts the specified array of ints into ascending order using TimSort algorithm and simultaneously permutes the coSort ints array in the same way as the target array.

        NOTE: using of this method is very good for large arrays with more then 100 elements, in other case using of insertion sort is highly recommended.

        This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort.

        The code was taken from Arrays.sort(java.lang.Object[]) and adapted for integers. For more information look there.

        Parameters:
        target - the array to be sorted
        coSort - the array which will be permuted in the same way as the target array during sorting procedure
        Throws:
        java.lang.ClassCastException - if the array contains elements that are not mutually comparable (for example, strings and integers)
        See Also:
        Arrays.sort(java.lang.Object[])
      • stableSort

        public static void stableSort(int[] target,
                                      int[] cosort)
        Sorts the specified array of ints into ascending order using stable sort algorithm and simultaneously permutes the coSort ints array in the same way as the target array. If length of specified array is less than 100 - insertion sort algorithm performed, otherwise - TimSort.

        This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort.

        Parameters:
        target - the array to be sorted
        cosort - the array which will be permuted in the same way as the target array during sorting procedure
        Throws:
        java.lang.ClassCastException - if the array contains elements that are not mutually comparable (for example, strings and integers)
        java.lang.IllegalArgumentException - if coSort length less then target length.
        java.lang.IllegalArgumentException - if target == coSort (as references).
        See Also:
        insertionSort(int[], int[]), timSort(int[], int[])
      • quickSortP

        public static int[] quickSortP(int[] target)
        Sorts the specified array and returns the resulting permutation
        Parameters:
        target - int array
        Returns:
        sorting permutation
      • quickSort

        public static void quickSort(int[] target,
                                     int[] coSort)
        Sorts the specified target array of ints into ascending numerical order and simultaneously permutes the coSort ints array in the same way as the target array.

        The code was taken from the jdk6 Arrays class.

        The sorting algorithm is a tuned quicksort, adapted from Jon L. Bentley and M. Douglas McIlroy's "Engineering a Sort Function", Software-Practice and Experience, Vol. 23(11) P. 1249-1265 (November 1993). This algorithm offers n*log(n) performance on many data sets that cause other quicksorts to degrade to quadratic performance.

        NOTE: remember this is unstable sort algorithm, so additional combinatorics of the coSort array can be perfomed. Use this method only if you are sure, in what you are doing. If not - use stable sort methods like an insertion sort or Tim sort.

        NOTE: The method throws IllegalArgumentException if target == coSort, because in this case no sorting will be perfomed.

        Parameters:
        target - the array to be sorted
        coSort - the array which will be permuted in the same way as the target array during sorting procedure
        Throws:
        java.lang.IllegalArgumentException - if coSort length less then target length.
        java.lang.IllegalArgumentException - if target == coSort (as references).
      • quickSort

        public static void quickSort(int[] target,
                                     int fromIndex,
                                     int toIndex,
                                     int[] coSort)
        Sorts the specified range of the specified target array of ints into ascending numerical order and simultaneously permutes the coSort ints array in the same way as the target array. The range to be sorted extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be sorted is empty.)

        The code was taken from the jdk6 Arrays class.

        The sorting algorithm is a tuned quicksort, adapted from Jon L. Bentley and M. Douglas McIlroy's "Engineering a Sort Function", Software-Practice and Experience, Vol. 23(11) P. 1249-1265 (November 1993). This algorithm offers n*log(n) performance on many data sets that cause other quicksorts to degrade to quadratic performance.

        NOTE: remember this is unstable sort algorithm, so additional combinatorics of the coSort array can be perfomed. Use this method only if you are sure, in what you are doing. If not - use stable sort methods like an insertion sort or Tim sort.

        NOTE: The method throws IllegalArgumentException if target == coSort, because in this case no sorting will be perfomed.

        Parameters:
        target - the array to be sorted
        fromIndex - the index of the first element (inclusive) to be sorted
        toIndex - the index of the last element (exclusive) to be sorted
        coSort - the array which will be permuted in the same way as the target array, during sorting procedure
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.ArrayIndexOutOfBoundsException - if fromIndex < 0 or toIndex > target.length or toIndex > coSort.length
        java.lang.IllegalArgumentException - if target == coSort (as references).
      • quickSort1

        public static void quickSort1(int[] target,
                                      int fromIndex,
                                      int length,
                                      int[] coSort)
        This method is the same as quickSort(int[], int, int, int[]), but without range checking and toIndex -> length (see params). Throws IllegalArgumentException if target == coSort, because in this case no sorting will be perfomed .

        NOTE: this is unstable sort algorithm, so additional combinatorics of the coSort array can be perfomed. Use this method only if you are sure, in what you are doing. If not - use stable sort methods like an insertion sort or Tim sort.

        Parameters:
        target - the array to be sorted
        fromIndex - the index of the first element (inclusive) to be sorted
        length - the length of the sorting subarray.
        coSort - the array which will be permuted in the same way as the target array, during sorting procedure
        Throws:
        java.lang.IllegalArgumentException - if target == coSort (as references).
      • swap

        public static void swap(int[] x,
                                int a,
                                int b)
        Swaps x[a] with x[b].
      • quickSort

        public static void quickSort(int[] target,
                                     long[] coSort)
        Sorts the specified target array of ints into ascending numerical order and simultaneously permutes the coSort longs array in the same way as the target array.

        The code was taken from the jdk6 Arrays class.

        The sorting algorithm is a tuned quicksort, adapted from Jon L. Bentley and M. Douglas McIlroy's "Engineering a Sort Function", Software-Practice and Experience, Vol. 23(11) P. 1249-1265 (November 1993). This algorithm offers n*log(n) performance on many data sets that cause other quicksorts to degrade to quadratic performance.

        NOTE: this is unstable sort algorithm, so additional combinatorics of the coSort array can be perfomed. Use this method only if you are sure, in what you are doing. If not - use stable sort methods like an insertion sort or Tim sort.

        Parameters:
        target - the array to be sorted
        coSort - the array which will be permuted in the same way as the target array during sorting procedure
        Throws:
        java.lang.IllegalArgumentException - if coSort length less then target length.
      • quickSort

        public static void quickSort(int[] target,
                                     int fromIndex,
                                     int toIndex,
                                     long[] coSort)
        Sorts the specified range of the specified target array of ints into ascending numerical order and simultaneously permutes the coSort longs array in the same way as the target array. The range to be sorted extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be sorted is empty.)

        The code was taken from the jdk6 Arrays class.

        The sorting algorithm is a tuned quicksort, adapted from Jon L. Bentley and M. Douglas McIlroy's "Engineering a Sort Function", Software-Practice and Experience, Vol. 23(11) P. 1249-1265 (November 1993). This algorithm offers n*log(n) performance on many data sets that cause other quicksorts to degrade to quadratic performance.

        NOTE: this is unstable sort algorithm, so additional combinatorics of the coSort array can be performed. Use this method only if you are sure, in what you are doing. If not - use stable sort methods like an insertion sort or Tim sort.

        Parameters:
        target - the array to be sorted
        fromIndex - the index of the first element (inclusive) to be sorted
        toIndex - the index of the last element (exclusive) to be sorted
        coSort - the array which will be permuted in the same way as the target array, during sorting procedure
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.ArrayIndexOutOfBoundsException - if fromIndex < 0 or toIndex > target.length or toIndex > coSort.length
      • quickSort1

        public static void quickSort1(int[] target,
                                      int fromIndex,
                                      int length,
                                      long[] coSort)
        This method is the same as ) , but without range checking.

        NOTE: this is unstable sort algorithm, so additional combinatorics of the coSort array can be performed. Use this method only if you are sure, in what you are doing. If not - use stable sort methods like an insertion sort or Tim sort.

        Parameters:
        target - the array to be sorted
        fromIndex - the index of the first element (inclusive) to be sorted
        length - the length of the sorting subarray.
        coSort - the array which will be permuted in the same way as the target array, during sorting procedure
      • quickSort

        public static <T extends java.lang.Comparable<T>> void quickSort(T[] target,
                                                                         java.lang.Object[] coSort)
        Sorts the specified target array of objects into ascending order, according to the natural ordering of its elements and simultaneously permutes the coSort objects array in the same way then specified target array.

        The code was taken from the jdk6 Arrays class.

        The sorting algorithm is a tuned quicksort, adapted from Jon L. Bentley and M. Douglas McIlroy's "Engineering a Sort Function", Software-Practice and Experience, Vol. 23(11) P. 1249-1265 (November 1993). This algorithm offers n*log(n) performance on many data sets that cause other quicksorts to degrade to quadratic performance.

        NOTE: this is unstable sort algorithm, so additional combinatorics of the coSort array can be perfomed. Use this method only if you are sure, in what you are doing. If not - use stable sort methods like an insertion sort or Tim sort.

        Parameters:
        target - the array to be sorted
        coSort - the array which will be permuted in the same way as the target array during sorting procedure
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.IllegalArgumentException - if coSort length less then target length.
        java.lang.IllegalArgumentException - if target == coSort (as references).
      • quickSort

        public static <T extends java.lang.Comparable<T>> void quickSort(T[] target,
                                                                         int fromIndex,
                                                                         int toIndex,
                                                                         java.lang.Object[] coSort)
        Sorts the specified target array of objects into ascending order, according to the natural ordering of its elements and simultaneously permutes the coSort objects array in the same way then specified target array. The range to be sorted extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be sorted is empty.)

        The code was taken from the jdk6 Arrays class.

        The sorting algorithm is a tuned quicksort, adapted from Jon L. Bentley and M. Douglas McIlroy's "Engineering a Sort Function", Software-Practice and Experience, Vol. 23(11) P. 1249-1265 (November 1993). This algorithm offers n*log(n) performance on many data sets that cause other quicksorts to degrade to quadratic performance.

        NOTE: this is unstable sort algorithm, so additional combinatorics of the coSort array can be perfomed. Use this method only if you are sure, in what you are doing. If not - use stable sort methods like an insertion sort or Tim sort.

        Parameters:
        target - the array to be sorted
        fromIndex - the index of the first element (inclusive) to be sorted
        toIndex - the index of the last element (exclusive) to be sorted
        coSort - the array which will be permuted in the same way as the target array, during sorting procedure
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.ArrayIndexOutOfBoundsException - if fromIndex < 0 or toIndex > target.length or toIndex > coSort.length
        java.lang.IllegalArgumentException - if target == coSort (as references).
      • quickSort1

        public static <T extends java.lang.Comparable<T>> void quickSort1(T[] target,
                                                                          int fromIndex,
                                                                          int length,
                                                                          java.lang.Object[] coSort)
        This method is the same as quickSort(Comparable[], int, int, Object[]), but without range checking.

        NOTE: this is unstable sort algorithm, so additional combinatorics of the coSort array can be perfomed. Use this method only if you are sure, in what you are doing. If not - use stable sort methods like an insertion sort or Tim sort.

        Parameters:
        target - the array to be sorted
        fromIndex - the index of the first element (inclusive) to be sorted
        length - the length of the sorting subarray.
        coSort - the array which will be permuted in the same way as the target array, during sorting procedure
        Throws:
        java.lang.IllegalArgumentException - if target == coSort (as references).
      • quickSort

        public static <T extends java.lang.Comparable<T>> void quickSort(T[] target,
                                                                         int[] coSort)
        Sorts the specified target array of objects into ascending order, according to the natural ordering of its elements and simultaneously permutes the coSort objects array in the same way then specified target array.

        The code was taken from the jdk6 Arrays class.

        The sorting algorithm is a tuned quicksort, adapted from Jon L. Bentley and M. Douglas McIlroy's "Engineering a Sort Function", Software-Practice and Experience, Vol. 23(11) P. 1249-1265 (November 1993). This algorithm offers n*log(n) performance on many data sets that cause other quicksorts to degrade to quadratic performance.

        NOTE: this is unstable sort algorithm, so additional combinatorics of the coSort array can be perfomed. Use this method only if you are sure, in what you are doing. If not - use stable sort methods like an insertion sort or Tim sort.

        Parameters:
        target - the array to be sorted
        coSort - the array which will be permuted in the same way as the target array during sorting procedure
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.IllegalArgumentException - if coSort length less then target length.
        java.lang.IllegalArgumentException - if target == coSort (as references).
      • quickSort

        public static <T extends java.lang.Comparable<T>> void quickSort(T[] target,
                                                                         int fromIndex,
                                                                         int toIndex,
                                                                         int[] coSort)
        Sorts the specified target array of objects into ascending order, according to the natural ordering of its elements and simultaneously permutes the coSort objects array in the same way then specified target array. The range to be sorted extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be sorted is empty.)

        The code was taken from the jdk6 Arrays class.

        The sorting algorithm is a tuned quicksort, adapted from Jon L. Bentley and M. Douglas McIlroy's "Engineering a Sort Function", Software-Practice and Experience, Vol. 23(11) P. 1249-1265 (November 1993). This algorithm offers n*log(n) performance on many data sets that cause other quicksorts to degrade to quadratic performance.

        NOTE: this is unstable sort algorithm, so additional combinatorics of the coSort array can be perfomed. Use this method only if you are sure, in what you are doing. If not - use stable sort methods like an insertion sort or Tim sort.

        Parameters:
        target - the array to be sorted
        fromIndex - the index of the first element (inclusive) to be sorted
        toIndex - the index of the last element (exclusive) to be sorted
        coSort - the array which will be permuted in the same way as the target array, during sorting procedure
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.ArrayIndexOutOfBoundsException - if fromIndex < 0 or toIndex > target.length or toIndex > coSort.length
        java.lang.IllegalArgumentException - if target == coSort (as references).
      • quickSort1

        public static <T extends java.lang.Comparable<T>> void quickSort1(T[] target,
                                                                          int fromIndex,
                                                                          int length,
                                                                          int[] coSort)
        This method is the same as quickSort(Comparable[], int, int, Object[]), but without range checking.

        NOTE: this is unstable sort algorithm, so additional combinatorics of the coSort array can be perfomed. Use this method only if you are sure, in what you are doing. If not - use stable sort methods like an insertion sort or Tim sort.

        Parameters:
        target - the array to be sorted
        fromIndex - the index of the first element (inclusive) to be sorted
        length - the length of the sorting subarray.
        coSort - the array which will be permuted in the same way as the target array, during sorting procedure
        Throws:
        java.lang.IllegalArgumentException - if target == coSort (as references).
      • swap

        public static void swap(java.lang.Object[] x,
                                int a,
                                int b)
        Swaps x[a] with x[b].
      • quickSort

        public static void quickSort(int[] target,
                                     java.lang.Object[] coSort)
        Sorts the specified target array of ints into ascending numerical order and simultaneously permutes the coSort Objects array in the same way as the target array.

        The code was taken from the jdk6 Arrays class.

        The sorting algorithm is a tuned quicksort, adapted from Jon L. Bentley and M. Douglas McIlroy's "Engineering a Sort Function", Software-Practice and Experience, Vol. 23(11) P. 1249-1265 (November 1993). This algorithm offers n*log(n) performance on many data sets that cause other quicksorts to degrade to quadratic performance.

        NOTE: this is unstable sort algorithm, so additional combinatorics of the coSort array can be perfomed. Use this method only if you are sure, in what you are doing. If not - use stable sort methods like an insertion sort or Tim sort.

        Parameters:
        target - the array to be sorted
        coSort - the array which will be permuted in the same way as the target array during sorting procedure
        Throws:
        java.lang.IllegalArgumentException - if coSort length less then target length.
      • quickSort

        public static void quickSort(int[] target,
                                     int fromIndex,
                                     int toIndex,
                                     java.lang.Object[] coSort)
        Sorts the specified range of the specified target array of ints into ascending numerical order and simultaneously permutes the coSort Objects array in the same way as the target array. The range to be sorted extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be sorted is empty.)

        The code was taken from the jdk6 Arrays class.

        The sorting algorithm is a tuned quicksort, adapted from Jon L. Bentley and M. Douglas McIlroy's "Engineering a Sort Function", Software-Practice and Experience, Vol. 23(11) P. 1249-1265 (November 1993). This algorithm offers n*log(n) performance on many data sets that cause other quicksorts to degrade to quadratic performance.

        NOTE: this is unstable sort algorithm, so additional combinatorics of the coSort array can be perfomed. Use this method only if you are sure, in what you are doing. If not - use stable sort methods like an insertion sort or Tim sort.

        Parameters:
        target - the array to be sorted
        fromIndex - the index of the first element (inclusive) to be sorted
        toIndex - the index of the last element (exclusive) to be sorted
        coSort - the array which will be permuted in the same way as the target array, during sorting procedure
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.ArrayIndexOutOfBoundsException - if fromIndex < 0 or toIndex > target.length or toIndex > coSort.length
      • quickSort1

        public static void quickSort1(int[] target,
                                      int fromIndex,
                                      int length,
                                      java.lang.Object[] coSort)
        This method is the same as ) , but without range checking.

        NOTE: this is unstable sort algorithm, so additional combinatorics of the coSort array can be perfomed. Use this method only if you are sure, in what you are doing. If not - use stable sort methods like an insertion sort or Tim sort.

        Parameters:
        target - the array to be sorted
        fromIndex - the index of the first element (inclusive) to be sorted
        length - the length of the sorting subarray.
        coSort - the array which will be permuted in the same way as the target array, during sorting procedure
      • quickSortP

        public static int[] quickSortP(short[] target)
      • quickSort

        public static void quickSort(short[] target,
                                     int fromIndex,
                                     int toIndex,
                                     int[] coSort)
        Sorts the specified range of the specified target array of ints into ascending numerical order and simultaneously permutes the coSort ints array in the same way as the target array. The range to be sorted extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be sorted is empty.)

        The code was taken from the jdk6 Arrays class.

        The sorting algorithm is a tuned quicksort, adapted from Jon L. Bentley and M. Douglas McIlroy's "Engineering a Sort Function", Software-Practice and Experience, Vol. 23(11) P. 1249-1265 (November 1993). This algorithm offers n*log(n) performance on many data sets that cause other quicksorts to degrade to quadratic performance.

        NOTE: remember this is unstable sort algorithm, so additional combinatorics of the coSort array can be perfomed. Use this method only if you are sure, in what you are doing. If not - use stable sort methods like an insertion sort or Tim sort.

        NOTE: The method throws IllegalArgumentException if target == coSort, because in this case no sorting will be perfomed.

        Parameters:
        target - the array to be sorted
        fromIndex - the index of the first element (inclusive) to be sorted
        toIndex - the index of the last element (exclusive) to be sorted
        coSort - the array which will be permuted in the same way as the target array, during sorting procedure
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.ArrayIndexOutOfBoundsException - if fromIndex < 0 or toIndex > target.length or toIndex > coSort.length
      • quickSort1

        public static void quickSort1(short[] target,
                                      int fromIndex,
                                      int length,
                                      int[] coSort)
        This method is the same as quickSort(int[], int, int, int[]), but without range checking and toIndex -> length (see params). Throws IllegalArgumentException if target == coSort, because in this case no sorting will be perfomed .

        NOTE: this is unstable sort algorithm, so additional combinatorics of the coSort array can be perfomed. Use this method only if you are sure, in what you are doing. If not - use stable sort methods like an insertion sort or Tim sort.

        Parameters:
        target - the array to be sorted
        fromIndex - the index of the first element (inclusive) to be sorted
        length - the length of the sorting subarray.
        coSort - the array which will be permuted in the same way as the target array, during sorting procedure
      • quickSort

        public static void quickSort(short[] target,
                                     int[] coSort)
        Sorts the specified target array of shorts into ascending numerical order and simultaneously permutes the coSort ints array in the same way as the target array.

        The code was taken from the jdk6 Arrays class.

        The sorting algorithm is a tuned quicksort, adapted from Jon L. Bentley and M. Douglas McIlroy's "Engineering a Sort Function", Software-Practice and Experience, Vol. 23(11) P. 1249-1265 (November 1993). This algorithm offers n*log(n) performance on many data sets that cause other quicksorts to degrade to quadratic performance.

        NOTE: remember this is unstable sort algorithm, so additional combinatorics of the coSort array can be perfomed. Use this method only if you are sure, in what you are doing. If not - use stable sort methods like an insertion sort or Tim sort.

        NOTE: The method throws IllegalArgumentException if target == coSort, because in this case no sorting will be perfomed.

        Parameters:
        target - the array to be sorted
        coSort - the array which will be permuted in the same way as the target array during sorting procedure
        Throws:
        java.lang.IllegalArgumentException - if coSort length less then target length.
      • quickSort

        public static void quickSort(int[] target,
                                     IntComparator comparator)
        Sorts the specified range of the specified target array of ints into order specified by IntComparator using quicksort.
        Parameters:
        target - the array to be sorted
        comparator - custom comparator
        Throws:
        java.lang.IllegalArgumentException - if coSort length less then target length.
      • quickSort

        public static void quickSort(int[] target,
                                     int fromIndex,
                                     int toIndex,
                                     IntComparator comparator)
        Sorts the specified range of the specified target array of ints into order specified by IntComparator using quicksort.
        Parameters:
        target - the array to be sorted
        fromIndex - the index of the first element (inclusive) to be sorted
        toIndex - the index of the last element (exclusive) to be sorted
        comparator - comparator
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.ArrayIndexOutOfBoundsException - if fromIndex < 0 or toIndex > target.length or toIndex > coSort.length
      • quickSort1

        public static void quickSort1(int[] target,
                                      int fromIndex,
                                      int length,
                                      IntComparator comparator)
        Sorts the specified range of the specified target array of ints into order specified by IntComparator using quicksort.
        Parameters:
        target - the array to be sorted
        fromIndex - the index of the first element (inclusive) to be sorted
        length - the length of the sorting subarray.
        comparator - comparator
      • quickSort

        public static void quickSort(int[] target,
                                     int[] cosort,
                                     IntComparator comparator)
        Sorts the specified target array of ints according to IntComparator and simultaneously permutes the coSort Objects array in the same way as the target array.

        The code was taken from the jdk6 Arrays class.

        The sorting algorithm is a tuned quicksort, adapted from Jon L. Bentley and M. Douglas McIlroy's "Engineering a Sort Function", Software-Practice and Experience, Vol. 23(11) P. 1249-1265 (November 1993). This algorithm offers n*log(n) performance on many data sets that cause other quicksorts to degrade to quadratic performance.

        NOTE: this is unstable sort algorithm, so additional combinatorics of the coSort array can be perfomed. Use this method only if you are sure, in what you are doing. If not - use stable sort methods like an insertion sort or Tim sort.

        Parameters:
        target - the array to be sorted
        comparator - custom comparator
        Throws:
        java.lang.IllegalArgumentException - if coSort length less then target length.
      • quickSort

        public static void quickSort(int[] target,
                                     int fromIndex,
                                     int toIndex,
                                     int[] cosort,
                                     IntComparator comparator)
        Sorts the specified range of the specified target array of ints according to IntComparator and simultaneously permutes the coSort Objects array in the same way as the target array. The range to be sorted extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be sorted is empty.)

        The code was taken from the jdk6 Arrays class.

        The sorting algorithm is a tuned quicksort, adapted from Jon L. Bentley and M. Douglas McIlroy's "Engineering a Sort Function", Software-Practice and Experience, Vol. 23(11) P. 1249-1265 (November 1993). This algorithm offers n*log(n) performance on many data sets that cause other quicksorts to degrade to quadratic performance.

        NOTE: this is unstable sort algorithm, so additional combinatorics of the coSort array can be perfomed. Use this method only if you are sure, in what you are doing. If not - use stable sort methods like an insertion sort or Tim sort.

        Parameters:
        target - the array to be sorted
        fromIndex - the index of the first element (inclusive) to be sorted
        toIndex - the index of the last element (exclusive) to be sorted
        comparator - comparator
        Throws:
        java.lang.IllegalArgumentException - if fromIndex > toIndex
        java.lang.ArrayIndexOutOfBoundsException - if fromIndex < 0 or toIndex > target.length or toIndex > coSort.length
      • toString

        public static <T> java.lang.String toString(T[] a,
                                                    ToStringConverter<T> format)
      • toString

        public static java.lang.String toString(int[] a,
                                                ToStringConverter<java.lang.Integer> format)

DataMelt 3.0 © DataMelt by jWork.ORG

Ads help maintain this website.