Here you can find the source of sortedPointersInto_tryingToImproveSpeed(final double d[])
public static int[] sortedPointersInto_tryingToImproveSpeed(final double d[])
//package com.java2s; //License from project: LGPL import java.util.Arrays; import java.util.Comparator; public class Main { public static int[] sortedPointersInto_tryingToImproveSpeed(final double d[]) { /*int pointers[] = new int[d.length]; for(int i=0; i<d.length; i++) pointers[i] = i; //TODO? Arrays.parallelSort(arg0); */// w ww .j a v a 2s . co m for (int i = 0; i < d.length; i++) { double x = d[i]; if (x != x) { //NaN, because it may be causing sorting inconsistency d[i] = Double.MAX_VALUE; } } Integer Ints[] = new Integer[d.length]; for (int i = 0; i < d.length; i++) Ints[i] = d.length - 1 - i; Comparator<Integer> compare = new Comparator<Integer>() { public int compare(Integer x, Integer y) { double xd = d[x], yd = d[y]; if (xd < yd) return -1; if (xd > yd) return 1; return 0; } }; /*while(true){ try{ Arrays.sort(Ints, compare); break; }catch(Exception e){ System.out.println("This is probably 'Comparison method violates its general contract' which strictfp avoids always singlethreaded but it appears some thread is using it, but which one could it be since its a local var? For now, since it happens only 1 20000 times its faster to just catch this and do it again those times. TODO find that thread and synchronize here and there! "+e.getMessage()); e.printStackTrace(System.out); } }*/ Arrays.sort(Ints, compare); int ints[] = new int[d.length]; for (int i = 0; i < d.length; i++) ints[i] = Ints[i]; return ints; } }