/** * Merge sort */ public static void msort(Object[] src, Object[] dest, Comparator comp){ msort(src, dest, 0, src.length - 1, comp); }
/** * 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); } }
for (int i = 0; i < 1000000; i++) { System.arraycopy(original, 0, sorted, 0, original.length); msort(original, sorted, ic);
/** * 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); } }
/** * Merge sort */ public static void msort(Object[] src, Object[] dest, Comparator comp){ msort(src, dest, 0, src.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. */ 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); } } }
/** * 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 * * @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); } }
for (int i = 0; i < 1000000; i++) { System.arraycopy(original, 0, sorted, 0, original.length); msort(original, sorted, ic);
for (int i = 0; i < 1000000; i++) { System.arraycopy(original, 0, sorted, 0, original.length); msort(original, sorted, ic);
/** * 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); } }
/** * Sorts the elements in the list acording 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); } }
SortUtil.msort(particles, particlesCopy, comparator); particles = particlesCopy;