public static void main(String[] argv) { Integer[] arr = new Integer[]{5, 6, 2, 9, 10, 11, 12, 8, 3, 12, 3, 7, 12, 32, 458, 12, 5, 3, 78, 45, 12, 32, 58, 45, 65, 45, 98, 45, 65, 2, 3, 47, 21, 35}; ListSort ls = new ListSort(); ls.allocateStack(34); ls.sort(arr, new Comparator<Integer>() { public int compare(Integer o1, Integer o2) { int x = o1 - o2; return (x == 0) ? 0 : (x > 0) ? 1 : -1; } }); for (Integer integer : arr) { System.err.print(integer + ","); } System.err.println(); }
this.array = array; this.comparator = comparator; clean(); int low = 0; int high = length; int runLength = getRunLength(array, low, high, comparator); binaryInsertionSort(array, low, high, low + runLength, comparator); return; int minLength = mergeComputeMinRun(remaining); while (remaining != 0) { int runLength = getRunLength(array, low, high, comparator); binaryInsertionSort(array, low, low + newLength, low + runLength, comparator); runLength = newLength; runsLength[nbRuns] = runLength; nbRuns++; mergeCollapse(); mergeForceCollapse();
int k = gallopRight(array[indexB], array, indexA, lenA, 0, comparator); indexA += k; lenA -= k; lenB = gallopLeft(array[indexA + lenA - 1], array, indexB, lenB, lenB - 1, comparator); if (lenB == 0) { return; mergeLow(indexA, lenA, indexB, lenB); } else { mergeHigh(indexA, lenA, indexB, lenB);
/** * Sorts the elements in the list according to their Comparator. */ public void sort() { if (size > 1) { // sort the spatial list using the comparator if(listSort.getLength() != size){ listSort.allocateStack(size); } listSort.sort(geometries,comparator); } }
aWins = gallopRight(arr[iterB], tempArray, iterA, lengthA, 0, comp); if (aWins != 0) { System.arraycopy(tempArray, iterA, arr, dest, aWins); bWins = gallopLeft(tempArray[iterA], arr, iterB, lengthB, 0, comp); if (bWins != 0) { System.arraycopy(arr, iterB, arr, dest, bWins);
/** * Initializes the GeometryList to use the given {@link GeometryComparator} * to use for comparing geometries. * * @param comparator The comparator to use. */ public GeometryList(GeometryComparator comparator) { size = 0; geometries = new Geometry[DEFAULT_SIZE]; this.comparator = comparator; listSort = new ListSort<Geometry>(); }
dest++; iterB++; innerMergeLow(comp, arr, tempArray);
dest--; iterA--; innerMergeHigh(comp, tempArray, arr, idxA);
/** * Sorts the elements in the list according to their Comparator. */ public void sort() { if (size > 1) { // sort the spatial list using the comparator if(listSort.getLength() != size){ listSort.allocateStack(size); } listSort.sort(geometries,comparator); } }
aWins = lengthA - gallopRight(tempArray[iterB], arr, idxA, lengthA, lengthA - 1, comp); if (aWins != 0) { dest -= aWins; bWins = lengthB - gallopLeft(arr[iterA], tempArray, 0, lengthB, lengthB - 1, comp); if (bWins != 0) { dest -= bWins;
/** * Initializes the GeometryList to use the given {@link GeometryComparator} * to use for comparing geometries. * * @param comparator The comparator to use. */ public GeometryList(GeometryComparator comparator) { size = 0; geometries = new Geometry[DEFAULT_SIZE]; this.comparator = comparator; listSort = new ListSort<Geometry>(); }
dest++; iterB++; innerMergeLow(comp, arr, tempArray);
dest--; iterA--; innerMergeHigh(comp, tempArray, arr, idxA);
this.array = array; this.comparator = comparator; clean(); int low = 0; int high = length; int runLength = getRunLength(array, low, high, comparator); binaryInsertionSort(array, low, high, low + runLength, comparator); return; int minLength = mergeComputeMinRun(remaining); while (remaining != 0) { int runLength = getRunLength(array, low, high, comparator); binaryInsertionSort(array, low, low + newLength, low + runLength, comparator); runLength = newLength; runsLength[nbRuns] = runLength; nbRuns++; mergeCollapse(); mergeForceCollapse();
int k = gallopRight(array[indexB], array, indexA, lenA, 0, comparator); indexA += k; lenA -= k; lenB = gallopLeft(array[indexA + lenA - 1], array, indexB, lenB, lenB - 1, comparator); if (lenB == 0) { return; mergeLow(indexA, lenA, indexB, lenB); } else { mergeHigh(indexA, lenA, indexB, lenB);
public static void main(String[] argv) { Integer[] arr = new Integer[]{5, 6, 2, 9, 10, 11, 12, 8, 3, 12, 3, 7, 12, 32, 458, 12, 5, 3, 78, 45, 12, 32, 58, 45, 65, 45, 98, 45, 65, 2, 3, 47, 21, 35}; ListSort ls = new ListSort(); ls.allocateStack(34); ls.sort(arr, new Comparator<Integer>() { public int compare(Integer o1, Integer o2) { int x = o1 - o2; return (x == 0) ? 0 : (x > 0) ? 1 : -1; } }); for (Integer integer : arr) { System.err.print(integer + ","); } System.err.println(); }
aWins = gallopRight(arr[iterB], tempArray, iterA, lengthA, 0, comp); if (aWins != 0) { System.arraycopy(tempArray, iterA, arr, dest, aWins); bWins = gallopLeft(tempArray[iterA], arr, iterB, lengthB, 0, comp); if (bWins != 0) { System.arraycopy(arr, iterB, arr, dest, bWins);
aWins = lengthA - gallopRight(tempArray[iterB], arr, idxA, lengthA, lengthA - 1, comp); if (aWins != 0) { dest -= aWins; bWins = lengthB - gallopLeft(arr[iterA], tempArray, 0, lengthB, lengthB - 1, comp); if (bWins != 0) { dest -= bWins;