for (int i = 0; i < 1000000; i++) { System.arraycopy(original, 0, sorted, 0, original.length); gsort(sorted, ic); for (int i = 0; i < 1000000; i++) { System.arraycopy(original, 0, sorted, 0, original.length); qsort(sorted, ic); for (int i = 0; i < 1000000; i++) { System.arraycopy(original, 0, sorted, 0, original.length); msort(original, sorted, ic);
/** * Merge sort * * @param src Source array * @param dest Destination array * @param low Index of beginning element * @param high Index of end element * @param comp Comparator */ public static void msort(Object[] src, Object[] dest, int low, int high, Comparator comp) { if(low < high) { int center = (low + high) / 2; msort(src, dest, low, center, comp); msort(src, dest, center + 1, high, comp); merge(src, dest, low, center + 1, high, comp); } }
public static void main(String[] args) { Comparator<Float> ic = new Comparator<Float>() { public int compare(Float o1, Float o2) { return (int) (o1 - o2); } }; Float[] original = new Float[]{2f, 1f, 5f, 3f, 4f, 6f, 8f, 9f, 11f, 10f, 12f, 13f, 14f, 15f, 7f, 19f, 20f, 18f, 16f, 17f, 21f, 23f, 22f, 24f, 25f, 27f, 26f, 29f, 28f, 30f, 31f}; Float[] sorted = new Float[original.length]; while (true) { test(original, sorted, ic); } }
/** * Quick sorts the supplied array using the specified comparator. */ public static void qsort(Object[] a, Comparator comp) { qsort(a, 0, a.length - 1, comp); }
/** * Merge sort */ public static void msort(Object[] src, Object[] dest, Comparator comp){ msort(src, dest, 0, src.length - 1, comp); }
/** * Sorts the elements in the list according to their Comparator. * There are two reasons why lights should be resorted. * First, if the lights have moved, that means their distance to * the spatial changed. * Second, if the spatial itself moved, it means the distance from it to * the individual lights might have changed. * * * @param transformChanged Whether the spatial's transform has changed */ public void sort(boolean transformChanged) { if (listSize > 1) { // resize or populate our temporary array as necessary if (tlist == null || tlist.length != list.length) { tlist = list.clone(); } else { System.arraycopy(list, 0, tlist, 0, list.length); } if (transformChanged){ // check distance of each light for (int i = 0; i < listSize; i++){ list[i].computeLastDistance(owner); } } // now merge sort tlist into list SortUtil.msort(tlist, list, 0, listSize - 1, c); } }
for (int i = 0; i < 1000000; i++) { System.arraycopy(original, 0, sorted, 0, original.length); gsort(sorted, ic); for (int i = 0; i < 1000000; i++) { System.arraycopy(original, 0, sorted, 0, original.length); qsort(sorted, ic); for (int i = 0; i < 1000000; i++) { System.arraycopy(original, 0, sorted, 0, original.length); msort(original, sorted, ic);
/** * Merge sort * * @param src Source array * @param dest Destination array * @param low Index of beginning element * @param high Index of end element * @param comp Comparator */ public static void msort(Object[] src, Object[] dest, int low, int high, Comparator comp) { if(low < high) { int center = (low + high) / 2; msort(src, dest, low, center, comp); msort(src, dest, center + 1, high, comp); merge(src, dest, low, center + 1, high, comp); } }
/** * Merge sort */ public static void msort(Object[] src, Object[] dest, Comparator comp){ msort(src, dest, 0, src.length - 1, comp); }
public static void main(String[] args) { Comparator<Float> ic = new Comparator<Float>() { public int compare(Float o1, Float o2) { return (int) (o1 - o2); } }; Float[] original = new Float[]{2f, 1f, 5f, 3f, 4f, 6f, 8f, 9f, 11f, 10f, 12f, 13f, 14f, 15f, 7f, 19f, 20f, 18f, 16f, 17f, 21f, 23f, 22f, 24f, 25f, 27f, 26f, 29f, 28f, 30f, 31f}; Float[] sorted = new Float[original.length]; while (true) { test(original, sorted, ic); } }
for (int i = 0; i < 1000000; i++) { System.arraycopy(original, 0, sorted, 0, original.length); gsort(sorted, ic); for (int i = 0; i < 1000000; i++) { System.arraycopy(original, 0, sorted, 0, original.length); qsort(sorted, ic); for (int i = 0; i < 1000000; i++) { System.arraycopy(original, 0, sorted, 0, original.length); msort(original, sorted, ic);
/** * Merge sort * * @param src Source array * @param dest Destination array * @param low Index of beginning element * @param high Index of end element * @param comp Comparator */ public static void msort(Object[] src, Object[] dest, int low, int high, Comparator comp) { if(low < high) { int center = (low + high) / 2; msort(src, dest, low, center, comp); msort(src, dest, center + 1, high, comp); merge(src, dest, low, center + 1, high, comp); } }
/** * Quick sorts the supplied array using the specified comparator. */ public static void qsort(Object[] a, Comparator comp) { qsort(a, 0, a.length - 1, comp); }
/** * Merge sort */ public static void msort(Object[] src, Object[] dest, Comparator comp){ msort(src, dest, 0, src.length - 1, comp); }
public static void main(String[] args) { Comparator<Float> ic = new Comparator<Float>() { public int compare(Float o1, Float o2) { return (int) (o1 - o2); } }; Float[] original = new Float[]{2f, 1f, 5f, 3f, 4f, 6f, 8f, 9f, 11f, 10f, 12f, 13f, 14f, 15f, 7f, 19f, 20f, 18f, 16f, 17f, 21f, 23f, 22f, 24f, 25f, 27f, 26f, 29f, 28f, 30f, 31f}; Float[] sorted = new Float[original.length]; while (true) { test(original, sorted, ic); } }
/** * Quick sorts the supplied array using the specified comparator. */ public static void qsort(Object[] a, Comparator comp) { qsort(a, 0, a.length - 1, comp); }
/** * Sorts the elements in the list according to their Comparator. */ public void sort() { if (size > 1) { // sort the spatial list using the comparator // SortUtil.qsort(geometries, 0, size, comparator); // Arrays.sort(geometries, 0, size, comparator); System.arraycopy(geometries, 0, geometries2, 0, size); SortUtil.msort(geometries2, geometries, 0, size-1, comparator); } } }