public final class ProxySorter extends Object
final double[] array = new Random().doubles(100).toArray();
final int[] proxy = ProxySorter.sort(array);
// 'Classical' array sort.
final double[] sorted = array.clone();
Arrays.sort(sorted);
// Iterating the array in ascending order.
for (int i = 0; i < array.length; ++i) {
assert sorted[i] == array[proxy[i]];
}
final IntFunction<String> access = ...;
final int length = 100;
final int[] proxy = ProxySorter.sort(
access, length,
(a, i, j) -> a.apply(i).compareTo(a.apply(j))
);
sort(Object, int, Comparator)
,
ProxySorter.Comparator
sort(Object, int, Comparator)
.
All other sorting methods can be created with this method.Modifier and Type | Class and Description |
---|---|
static interface |
ProxySorter.Comparator<T>
The comparator used for comparing two array elements at the specified
indexes.
|
Modifier and Type | Method and Description |
---|---|
static int[] |
sort(double[] array)
Sorting the given array by creating an index lookup array.
|
static int[] |
sort(int[] array)
Sorting the given array by creating an index lookup array.
|
static <T extends Comparable<? super T>> |
sort(List<? extends T> array)
Sorting the given array by creating an index lookup array.
|
static <T> int[] |
sort(List<? extends T> array,
Comparator<? super T> comparator)
Sorting the given array by creating an index lookup array.
|
static int[] |
sort(long[] array)
Sorting the given array by creating an index lookup array.
|
static <T extends Comparable<? super T>> |
sort(Seq<? extends T> array)
Sorting the given array by creating an index lookup array.
|
static <T> int[] |
sort(Seq<? extends T> array,
Comparator<? super T> comparator)
Sorting the given array by creating an index lookup array.
|
static <T extends Comparable<? super T>> |
sort(T[] array)
Sorting the given array by creating an index lookup array.
|
static <T> int[] |
sort(T[] array,
Comparator<? super T> comparator)
Sorting the given array by creating an index lookup array.
|
static <T> int[] |
sort(T array,
int length,
ProxySorter.Comparator<? super T> comparator)
Sorting the given array by creating an index lookup array.
|
public static <T> int[] sort(T array, int length, ProxySorter.Comparator<? super T> comparator)
final double[] array = ...;
final int[] sorted = ProxySorter.sort(
array, array.length,
(a, i, j) -> Doubler.compare(a[i], a[j])
);
for (int i : sorted) {
System.out.println(array[i]);
}
T
- the array typearray
- the array which is sortedlength
- the array lengthcomparator
- the array element comparatorNullPointerException
- if one of the array is null
public static int[] sort(int[] array)
array
- the array to sortNullPointerException
- if the array is null
sort(Object, int, Comparator)
public static int[] sort(long[] array)
array
- the array to sortNullPointerException
- if the array is null
sort(Object, int, Comparator)
public static int[] sort(double[] array)
array
- the array to sortNullPointerException
- if the array is null
sort(Object, int, Comparator)
public static <T> int[] sort(T[] array, Comparator<? super T> comparator)
T
- the array element typearray
- the array to sortcomparator
- the array element comparatorNullPointerException
- if one of the arguments is null
sort(Object, int, Comparator)
public static <T extends Comparable<? super T>> int[] sort(T[] array)
T
- the array element typearray
- the array to sortNullPointerException
- if the array is null
sort(Object, int, Comparator)
public static <T> int[] sort(Seq<? extends T> array, Comparator<? super T> comparator)
T
- the array element typearray
- the array to sortcomparator
- the array element comparatorNullPointerException
- if one of the arguments is null
sort(Object, int, Comparator)
public static <T extends Comparable<? super T>> int[] sort(Seq<? extends T> array)
T
- the array element typearray
- the array to sortNullPointerException
- if the array is null
sort(Object, int, Comparator)
public static <T> int[] sort(List<? extends T> array, Comparator<? super T> comparator)
T
- the array element typearray
- the array to sortcomparator
- the array element comparatorNullPointerException
- if one of the arguments is null
sort(Object, int, Comparator)
public static <T extends Comparable<? super T>> int[] sort(List<? extends T> array)
T
- the array element typearray
- the array to sortNullPointerException
- if the array is null
sort(Object, int, Comparator)
© 2007-2019 Franz Wilhelmstötter (2019-11-18 20:30)