added generic SortPermutation that returns sorting permutation for arbitrary List<T> as long as T is Comparable
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@144 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
09d605bb37
commit
38f18c8679
|
|
@ -280,6 +280,27 @@ public class Utils {
|
||||||
return permutation;
|
return permutation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <T extends Comparable> Integer[] SortPermutation( List<T> A )
|
||||||
|
{
|
||||||
|
final Object[] data = A.toArray();
|
||||||
|
|
||||||
|
class comparator implements Comparator<Integer>
|
||||||
|
{
|
||||||
|
public int compare(Integer a, Integer b)
|
||||||
|
{
|
||||||
|
return ((T)data[a]).compareTo(data[b]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Integer[] permutation = new Integer[A.size()];
|
||||||
|
for (int i = 0; i < A.size(); i++)
|
||||||
|
{
|
||||||
|
permutation[i] = i;
|
||||||
|
}
|
||||||
|
Arrays.sort(permutation, new comparator());
|
||||||
|
return permutation;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static int[] PermuteArray(int[] array, Integer[] permutation)
|
public static int[] PermuteArray(int[] array, Integer[] permutation)
|
||||||
{
|
{
|
||||||
int[] output = new int[array.length];
|
int[] output = new int[array.length];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue