public final class IndirectSort
extends java.lang.Object
A practical use case for this class is when the index of an array is meaningful and one
wants to acquire the order of values in that array. None of the methods in Java
Collections would provide such functionality directly and creating a collection of
boxed Integer objects for indices seems to be too costly.
| Modifier and Type | Method and Description |
|---|---|
static int[] |
mergesort(int start,
int length,
IndirectComparator comparator)
Returns the order of elements between indices
start and
start + length excluded, as indicated by the given comparator. |
static void |
mergesort(int start,
int length,
IndirectComparator comparator,
int[] tmpArray,
int[] sorted)
Returns the order of elements between indices
start and
start + length excluded, as indicated by the given comparator. |
static <T> int[] |
mergesort(T[] input,
int start,
int length,
java.util.Comparator<? super T> comparator)
Returns the order of elements between indices
start and
length + start excluded, as indicated by the given comparator. |
static void |
quicksort(int start,
int length,
IndirectComparator comparator,
int[] sorted)
Returns the order of elements between indices
start and
start + length excluded, as indicated by the given comparator. |
public static int[] mergesort(int start,
int length,
IndirectComparator comparator)
start and
start + length excluded, as indicated by the given comparator.
This routine uses merge sort. It is guaranteed to be stable. Take note this method generate temporaries.
public static void mergesort(int start,
int length,
IndirectComparator comparator,
int[] tmpArray,
int[] sorted)
start and
start + length excluded, as indicated by the given comparator.
This method entirely work by using pre-existing arrays, so is fitting for realtime.
This routine uses merge sort. It is guaranteed to be stable.
tmpArray - : a temporary array for usage in intermediate computation, its size must be >= lengthsorted - : the sorted indices result. The array must be at least of size length,
and the real validity range is [0; length[public static void quicksort(int start,
int length,
IndirectComparator comparator,
int[] sorted)
start and
start + length excluded, as indicated by the given comparator.
This method entirely work in-place, so is fitting for realtime.
This routine uses Dual-pivot Quicksort, from [Yaroslavskiy 2009], so is NOT stable.
sorted - : the sorted indices result. The array must be at least of size length,
and the real validity range is [0; length[public static <T> int[] mergesort(T[] input,
int start,
int length,
java.util.Comparator<? super T> comparator)
start and
length + start excluded, as indicated by the given comparator. This method
is equivalent to calling mergesort(int, int, IndirectComparator) with
IndirectComparator.DelegatingComparator.
This routine uses merge sort. It is guaranteed to be stable.
Take note this method generate temporaries.Copyright © 2017. All rights reserved.