public class SortUtils extends Object
getIterator(p, data) to iterate in sorted order.
A code example may show you what to do next:
String[] colors = { "red", "green", "blue" };
int[] p = SortUtils.sort(colors, new StringComparator());
// --> (colors[p[0]], colors[p[1]], colors[p[2]]) == ("blue","green","red")
Iterator iter = SortUtils.getIterator(p, colors)
// --> (iter.next(), iter.next(), iter.next()) == ("blue","green","red")
SortUtils.permute(SortUtils.inverse(p), colors, true);
// --> (colors[0], colors[1], colors[2]) == ("blue","green","red")
Stable sorts (preserving order of equal elements) are supported.
Sorting is done using quick-sort mith median of 3 (and insertion-sort
for small ranges).| Constructor and Description |
|---|
SortUtils() |
| Modifier and Type | Method and Description |
|---|---|
static Iterator |
getIterator(int[] p,
List data)
Answer iterator, which iterates over specified data list according
to the specified permutation, that is
data.get(p[0]),..,data.get(p[data.length-1]) |
static Iterator |
getIterator(int[] p,
Object[] data)
Answer iterator, which iterates over specified data array according
to the specified permutation, that is
data[p[0]],..,data[p[data.length-1]] |
static int[] |
identity(int n)
Create identity permutation, that is
{0, 1, ..., n} |
static int[] |
inverse(int[] p)
Compute inverse permutation
|
static void |
main(String[] args)
Test method
|
static Object[] |
permute(int[] p,
Object[] data,
boolean clone)
Rearrange the specified data according to the specified permutation.
|
static int[] |
reverse(int n)
Create reverse permutation, that is
{n-1, .... |
static void |
sort(int[] indices,
Object[] data,
Comparator comparator)
Do an unstable sort.
|
static void |
sort(int[] indices,
Object[] data,
Comparator comparator,
boolean stable)
Do a sort on indices.
|
static int[] |
sort(Object[] data,
Comparator comparator)
Do an unstable sort.
|
static int[] |
sort(Object[] data,
Comparator comparator,
boolean stable)
Do a sort on indices.
|
public static int[] identity(int n)
{0, 1, ..., n}public static int[] reverse(int n)
{n-1, .... 1, 0}public static int[] inverse(int[] p)
public static Object[] permute(int[] p, Object[] data, boolean clone)
data_after[p[i]] == data_before[i].data - data to be permutedp - the permutationclone - if true, rearrange a clone instead of the original data;public static Iterator getIterator(int[] p, Object[] data)
data[p[0]],..,data[p[data.length-1]]public static Iterator getIterator(int[] p, List data)
data.get(p[0]),..,data.get(p[data.length-1])public static void sort(int[] indices,
Object[] data,
Comparator comparator,
boolean stable)
data - data to be sortedcomparator - comparator to usestable - do a stable sort iff trueindices - into data (any permutation of 0,..data.length-1).public static int[] sort(Object[] data, Comparator comparator, boolean stable)
data - data to be sortedcomparator - comparator to usestable - do a stable sort iff truepublic static int[] sort(Object[] data, Comparator comparator)
data - data to be sortedcomparator - comparator to usepublic static void sort(int[] indices,
Object[] data,
Comparator comparator)
data - data to be sortedindices - into data (permutation of 0,..data.length-1).public static void main(String[] args)
DMelt 2.0 © DataMelt by jWork.ORG