Class XSort
public final class XSort extends Object
- 
Method SummaryModifier and Type Method Description static voidbufferDistinctsort(int[] values, int[] buffer)static <E> voidbufferDistinctsort(E[] values, E[] buffer, Comparator<? super E> comparator)static <E> E[]bufferedAdaptiveMergesort(E[] elements, E[] buffer, int start, int bound, Comparator<? super E> comparator)Subranged version ofbufferedAdaptiveMergesort(Object[], Object[], Comparator).static <E> E[]bufferedAdaptiveMergesort(E[] elements, E[] buffer, Comparator<? super E> comparator)Variation ofsort(Object[], Comparator)that allows to pass an additional array to be used as the sorting algorithm's internal buffer.static <E> E[]bufferMergesort(E[] values, E[] buffer, int start, int bound, Comparator<? super E> comparator)static <E> E[]bufferMergesort(E[] values, E[] buffer, Comparator<? super E> comparator)static <E> Comparator<? super E>chain(Comparator<? super E>... comparators)static intcompare(Boolean o1, Boolean o2)static intcompare(Byte o1, Byte o2)static intcompare(Double o1, Double o2)static intcompare(Float o1, Float o2)static intcompare(Integer o1, Integer o2)static intcompare(Long o1, Long o2)static intcompare(Short o1, Short o2)static intcompare(String o1, String o2)static intcompareIdentityHash(Object o1, Object o2)static intcompareLength(String o1, String o2)static voidcopyDistinctsort(int[] values, int[] target)static voiddistinctsort(int[] values)static <E> voiddistinctsort(E[] values, Comparator<? super E> comparator)static <E> voiddistinctsortInto(E[] values, E[] target, Comparator<? super E> comparator)static voidinsertionsort(boolean[] values)static voidinsertionsort(byte[] values)static voidinsertionsort(char[] values)static voidinsertionsort(double[] values)static voidinsertionsort(float[] values)static voidinsertionsort(int[] values)static voidinsertionsort(long[] values)static voidinsertionsort(short[] values)static <E> voidinsertionsort(E[] values, Comparator<? super E> comparator)static booleanisDecreasing(int[] values)static booleanisDecreasing(int[] values, int startIndex, int endIndex)static booleanisIncreasing(int[] values)static booleanisIncreasing(int[] values, int startIndex, int endIndex)static <E> booleanisReverseSorted(E[] values, int startIndex, int endIndex, Comparator<? super E> comparator)static <E> booleanisSorted(E[] values, Comparator<? super E> comparator)static booleanisStrictlyDecreasing(int[] values)static booleanisStrictlyDecreasing(int[] values, int startIndex, int endIndex)static booleanisStrictlyIncreasing(int[] values)static booleanisStrictlyIncreasing(int[] values, int startIndex, int endIndex)static <E> booleanisStrictlyReverseSorted(E[] values, int startIndex, int endIndex, Comparator<? super E> comparator)static <E> booleanisStrictlySorted(E[] values, Comparator<? super E> comparator)static <E> voidmergesort(E[] values, int start, int bound, Comparator<? super E> comparator)static <E> voidmergesort(E[] values, Comparator<? super E> comparator)static <E> voidparallelSort(E[] elements, Comparator<? super E> comparator)Experimental parallel sorting that splits the sorting work up into two parts.static <E> voidquicksort(E[] values, int start, int bound, Comparator<? super E> comparator)static <E> voidquicksort(E[] values, Comparator<? super E> comparator)static voidquicksortDualPivot(int[] values)static <E> voidquicksortDualPivot(E[] values, Comparator<? super E> comparator)static <E> Comparator<E>reverse(Comparator<E> comparator)static voidsort(int[] values)Sorts the passed values array.static voidsort(int[] values, int start, int bound)Subranged version ofsort(int[]).static voidsort(long[] values)static <E> voidsort(E[] elements, int start, int bound, Comparator<? super E> comparator)Subranged version ofsort(Object[], Comparator).static <E> voidsort(E[] elements, Comparator<? super E> comparator)Sorts the passed array as true instances (i.e.static <T> voidsortAll(Comparator<? super T> sortation, Sortable<T>... sortables)static doubleuniformity(int... values)static intuniformitySimple(int... values)Returns the number of subsequent equal values.static <V> voidvalueSort(XSortableSequence<V> values, Comparator<? super V> comparator)static <V> voidvalueSort(V[] values, int start, int bound, Comparator<? super V> comparator)Subranged version ofvalueSort(Object[], Comparator).static <V> voidvalueSort(V[] values, Comparator<? super V> comparator)Sorts the passed array as values (i.e.
- 
Method Details- 
compare
- 
compare
- 
compare
- 
compare
- 
compare
- 
compare
- 
compare
- 
compare
- 
compareLength
- 
compareIdentityHash
- 
reverse
- 
chain@SafeVarargs public static final <E> Comparator<? super E> chain(Comparator<? super E>... comparators)
- 
sortAll@SafeVarargs public static final <T> void sortAll(Comparator<? super T> sortation, Sortable<T>... sortables)
- 
insertionsortpublic static void insertionsort(boolean[] values)
- 
insertionsortpublic static void insertionsort(byte[] values)
- 
insertionsortpublic static void insertionsort(short[] values)
- 
insertionsortpublic static void insertionsort(int[] values)
- 
insertionsortpublic static void insertionsort(long[] values)
- 
insertionsortpublic static void insertionsort(float[] values)
- 
insertionsortpublic static void insertionsort(double[] values)
- 
insertionsortpublic static void insertionsort(char[] values)
- 
insertionsort
- 
sortSorts the passed array as true instances (i.e. with a stable sorting algorithm) that adapts to already sorted or nearly sorted order.This method is best used as a general purpose sort. For a subranged version, see sort(Object[], int, int, Comparator).Due to sorting the passed array in a stable and fast (O(n log(n)) fashion, each call of this method instantiates an internal buffer array with the same size as the passed array. If the repeated creation of buffer arrays shall be prevented, use bufferedAdaptiveMergesort(Object[], Object[], Comparator)to explicitly provide a reusable buffer.If maintaining the original order of equal elements (stability) is not required, valueSort(Object[], Comparator)usually yields better performance and also does not require additional storage space by using an unstable sorting algorithm.
 Note that unstable sorting algorithms can achieve stable results, too, if the passed array contains only distinct elements (e.g. the content of a set) or if all equal elements are just references to the same instance.- Type Parameters:
- E- the type of the elements to be sorted.
- Parameters:
- elements- the elements to be sorted.
- comparator- the- Comparatordefining the sortation order of the elements.
- See Also:
- valueSort(Object[], Comparator),- bufferedAdaptiveMergesort(Object[], Object[], Comparator),- sort(Object[], int, int, Comparator)
 
- 
sortSubranged version ofsort(Object[], Comparator).Example: sort(myElements, 0, 5, myElementComparatorsorts the first 5 elements of arraymyElements(indices 0 to 4).For further information, see sort(Object[], Comparator).- Type Parameters:
- E- the type of the elements to be sorted.
- Parameters:
- elements- the elements to be sorted.
- start- the starting index (inclusive) of the subrange to be sorted.
- bound- the bounding index (exclusive) of the subrange to be sorted.
- comparator- the- Comparatordefining the sortation order of the elements.
 
- 
valueSort
- 
valueSortSorts the passed array as values (i.e. with an unstable sorting algorithm).This method is best used for sorting arrays where stability is not important of that consist only of distinct values of equal values that actually are just duplicate references to the same instance. For a subranged version, see valueSort(Object[], int, int, Comparator).The used algorithm works inplace, i.e. does not instantiate any additional instances. If maintaining the original order of equal elements (stability) is required, sort(Object[], Comparator)has to be used instead, which maintains stability at the cost of performance and the need of additional temporary storage.- Type Parameters:
- V- the type of the values to be sorted.
- Parameters:
- values- the values to be sorted.
- comparator- the- Comparatordefining the sortation order of the values.
 
- 
valueSortpublic static <V> void valueSort(V[] values, int start, int bound, Comparator<? super V> comparator)Subranged version ofvalueSort(Object[], Comparator).Example: valueSort(myValues, 0, 5, myvalueComparatorsorts the first 5 values of arraymyElements(indices 0 to 4).For further information, see sort(Object[], Comparator).- Type Parameters:
- V- the type of the values to be sorted.
- Parameters:
- values- the values to be sorted.
- start- the starting index (inclusive) of the subrange to be sorted.
- bound- the bounding index (exclusive) of the subrange to be sorted.
- comparator- the- Comparatordefining the sortation order of the elements.
 
- 
bufferedAdaptiveMergesortpublic static <E> E[] bufferedAdaptiveMergesort(E[] elements, E[] buffer, Comparator<? super E> comparator)Variation ofsort(Object[], Comparator)that allows to pass an additional array to be used as the sorting algorithm's internal buffer.Use this method if the repeated buffer array instantiation of sort(Object[], Comparator)causes problems.If the passed buffer array is too small, a new buffer array of appropriate size is instantiated. The buffer (NOT the sorted array!) is returned. The buffer array is NOT cleared after the sorting is completed and may contain partial and inconsistent intermediate results. It is the external buffer array provider's responsibility to ensure programmatically correctness and memory leak avoidance for any content that might remain in the buffer array. - Type Parameters:
- E- the type of the elements to be sorted.
- Parameters:
- elements- the array containing the elements to be sorted.
- buffer- the array to be used as a buffer by the sorting algorithm.
- comparator- the comparator defining the sortation order of the elements.
- Returns:
- the passed buffer array or the newly created buffer array if the passed buffer array was too small.
- See Also:
- sort(Object[], Comparator),- bufferedAdaptiveMergesort(Object[], Object[], int, int, Comparator)
 
- 
bufferedAdaptiveMergesortpublic static <E> E[] bufferedAdaptiveMergesort(E[] elements, E[] buffer, int start, int bound, Comparator<? super E> comparator)Subranged version ofbufferedAdaptiveMergesort(Object[], Object[], Comparator).Example: bufferSort(myElements, 0, 5, myElementComparatorsorts the first 5 elements of arraymyElements(indices 0 to 4).For further information, see sort(Object[], Comparator).- Type Parameters:
- E- the type of the elements to be sorted.
- Parameters:
- elements- the elements to be sorted.
- buffer- the array to be used as a buffer by the sorting algorithm.
- start- the starting index (inclusive) of the subrange to be sorted.
- bound- the bounding index (exclusive) of the subrange to be sorted.
- comparator- the- Comparatordefining the sortation order of the elements.
- Returns:
- the passed buffer array or the newly created buffer array if the passed buffer array was too small.
 
- 
parallelSortExperimental parallel sorting that splits the sorting work up into two parts.As the work to do has to be big enough to pay off, the algorithm is capped at a certain minimum length (hardcoded 8192 at the moment) under which a normal singlethreaded sorting is executed. Really notable performance gain is achieved for lengths above 10.000. Length above 1 million yields performance boosts around 40% to 100%. - Type Parameters:
- E- the type of the elements to be sorted.
- Parameters:
- elements- the elements to be sorted.
- comparator- the- Comparatordefining the sortation order of the elements.
 
- 
sortSorts the passed values array.For a subranged version, see sort(int[], int, int).The used algorithm works inplace, i.e. does not instantiate any additional instances. - Parameters:
- values- the values to be sorted.
- Throws:
- NullPointerException
 
- 
sort- Throws:
- NullPointerException
 
- 
sortpublic static final void sort(int[] values, int start, int bound) throws NullPointerException, ArrayIndexOutOfBoundsExceptionSubranged version ofsort(int[]).Example: sort(myValues, 0, 5sorts the first 5 values of arraymyElements(indices 0 to 4).For further information, see sort(int[]).- Parameters:
- values- the values to be sorted.
- start- the starting index (inclusive) of the subrange to be sorted.
- bound- the bounding index (exclusive) of the subrange to be sorted.
- Throws:
- NullPointerException
- ArrayIndexOutOfBoundsException
 
- 
quicksortpublic static final <E> void quicksort(E[] values, Comparator<? super E> comparator) throws NullPointerException- Throws:
- NullPointerException
 
- 
quicksortpublic static final <E> void quicksort(E[] values, int start, int bound, Comparator<? super E> comparator) throws NullPointerException- Throws:
- NullPointerException
 
- 
mergesort
- 
mergesortpublic static <E> void mergesort(E[] values, int start, int bound, Comparator<? super E> comparator)
- 
bufferMergesort
- 
bufferMergesortpublic static <E> E[] bufferMergesort(E[] values, E[] buffer, int start, int bound, Comparator<? super E> comparator)
- 
distinctsortpublic static void distinctsort(int[] values)
- 
copyDistinctsortpublic static void copyDistinctsort(int[] values, int[] target)
- 
bufferDistinctsortpublic static void bufferDistinctsort(int[] values, int[] buffer)
- 
distinctsort
- 
bufferDistinctsortpublic static <E> void bufferDistinctsort(E[] values, E[] buffer, Comparator<? super E> comparator)
- 
distinctsortInto
- 
quicksortDualPivotpublic static void quicksortDualPivot(int[] values)
- 
quicksortDualPivot
- 
isIncreasingpublic static boolean isIncreasing(int[] values)
- 
isStrictlyIncreasingpublic static boolean isStrictlyIncreasing(int[] values)
- 
isDecreasingpublic static boolean isDecreasing(int[] values)
- 
isStrictlyDecreasingpublic static boolean isStrictlyDecreasing(int[] values)
- 
isIncreasingpublic static boolean isIncreasing(int[] values, int startIndex, int endIndex)
- 
isStrictlyIncreasingpublic static boolean isStrictlyIncreasing(int[] values, int startIndex, int endIndex)
- 
isDecreasingpublic static boolean isDecreasing(int[] values, int startIndex, int endIndex)
- 
isStrictlyDecreasingpublic static boolean isStrictlyDecreasing(int[] values, int startIndex, int endIndex)
- 
isSorted
- 
isStrictlySorted
- 
isReverseSortedpublic static <E> boolean isReverseSorted(E[] values, int startIndex, int endIndex, Comparator<? super E> comparator)
- 
isStrictlyReverseSortedpublic static <E> boolean isStrictlyReverseSorted(E[] values, int startIndex, int endIndex, Comparator<? super E> comparator)
- 
uniformitySimplepublic static int uniformitySimple(int... values)Returns the number of subsequent equal values.Examples: 
 uniformity(1,2,3,4,5) == 0
 uniformity(1,1,1,1,1) == 5
 uniformity(1,1,1,2,2) == 3
 uniformity(1,1,3,2,2) == 2- Parameters:
- values- the values whose uniformity shall be calculated
- Returns:
- the uniformity count.
 
- 
uniformitypublic static double uniformity(int... values)
 
-