Java Array Sort sortedPointersInto_usingStrictfp(final double d[])

Here you can find the source of sortedPointersInto_usingStrictfp(final double d[])

Description

strictfp needed to avoid violating Comparator.

License

LGPL

Declaration

public static strictfp int[] sortedPointersInto_usingStrictfp(final double d[]) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.util.Arrays;

import java.util.Comparator;

public class Main {
    /** strictfp needed to avoid violating Comparator.
    TODO This function, probably the strictfp part,
    is taking 3 times as much cpu time in physicsmata2.0.0 as the automata.
    *///from  w  w  w . j  a v a2  s. c o  m
    public static strictfp int[] sortedPointersInto_usingStrictfp(final double d[]) {
        Integer Ints[] = new Integer[d.length];
        for (int i = 0; i < d.length; i++)
            Ints[i] = i;
        Comparator<Integer> compare = new Comparator<Integer>() {
            public strictfp 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);
            }
        }
        int ints[] = new int[d.length];
        for (int i = 0; i < d.length; i++)
            ints[i] = Ints[i];
        return ints;
    }
}

Related

  1. sortedIndexOf(Comparable[] list, Comparable val, int lower, int higher)
  2. sortedMerge(int[] a, int[] b)
  3. sortedMerge(int[] aIds, double[] aVals, int[] bIds, double[] bVals, int[] resIds, double[] resVals)
  4. sortedPointersInto(double d[])
  5. sortedPointersInto_tryingToImproveSpeed(final double d[])
  6. sortEigenValues(int n, double[] d, double[][] v)
  7. sortIndex(double[] A)
  8. sortIndex(double[] doubleArray)
  9. sortIndexes(final T[] array)