/** * Swaps the element of the given big array of specified indices. * * @param array a big array. * @param first a position in the big array. * @param second a position in the big array. */ public static void swap(final int[][] array, final long first, final long second) { final int t = array[segment(first)][displacement(first)]; array[segment(first)][displacement(first)] = array[segment(second)][displacement(second)]; array[segment(second)][displacement(second)] = t; }
public void sort(int from, int to, IntComparator comparator) { IntBigArrays.quickSort(array, from, to, comparator); } }
private static void vecSwap(final int[][] x, long a, long b, final long n) { for (int i = 0; i < n; i++, a++, b++) { swap(x, a, b); } }
selectionSort(x, from, to, comp); return; if (len > MEDIUM) { // Big arrays, pseudomedian of 9 long s = len / 8; l = med3(x, l, l + s, l + 2 * s, comp); m = med3(x, m - s, m, m + s, comp); n = med3(x, n - 2 * s, n - s, n, comp); m = med3(x, l, m, n, comp); // Mid-size, med of 3 final int v = get(x, m); while (true) { int comparison; while (b <= c && (comparison = comp.compare(get(x, b), v)) <= 0) { if (comparison == 0) { swap(x, a++, b); while (c >= b && (comparison = comp.compare(get(x, c), v)) >= 0) { if (comparison == 0) { swap(x, c, d--); swap(x, b++, c--); long n = to; s = Math.min(a - from, b - a); vecSwap(x, from, b - s, s); s = Math.min(d - c, n - d - 1);
private static void selectionSort(final int[][] a, final long from, final long to, final IntComparator comp) { for (long i = from; i < to - 1; i++) { long m = i; for (long j = i + 1; j < to; j++) { if (comp.compare(IntBigArrays.get(a, j), IntBigArrays.get(a, m)) < 0) { m = j; } } if (m != i) { swap(a, i, m); } } } }
private static long med3(final int[][] x, final long a, final long b, final long c, IntComparator comp) { int ab = comp.compare(get(x, a), get(x, b)); int ac = comp.compare(get(x, a), get(x, c)); int bc = comp.compare(get(x, b), get(x, c)); return (ab < 0 ? (bc < 0 ? b : ac < 0 ? c : a) : (bc > 0 ? b : ac > 0 ? c : a)); }
selectionSort(x, from, to, comp); return; if (len > MEDIUM) { // Big arrays, pseudomedian of 9 long s = len / 8; l = med3(x, l, l + s, l + 2 * s, comp); m = med3(x, m - s, m, m + s, comp); n = med3(x, n - 2 * s, n - s, n, comp); m = med3(x, l, m, n, comp); // Mid-size, med of 3 final int v = get(x, m); while (true) { int comparison; while (b <= c && (comparison = comp.compare(get(x, b), v)) <= 0) { if (comparison == 0) { swap(x, a++, b); while (c >= b && (comparison = comp.compare(get(x, c), v)) >= 0) { if (comparison == 0) { swap(x, c, d--); swap(x, b++, c--); long n = to; s = Math.min(a - from, b - a); vecSwap(x, from, b - s, s); s = Math.min(d - c, n - d - 1);
private static void selectionSort(final int[][] a, final long from, final long to, final IntComparator comp) { for (long i = from; i < to - 1; i++) { long m = i; for (long j = i + 1; j < to; j++) { if (comp.compare(IntBigArrays.get(a, j), IntBigArrays.get(a, m)) < 0) { m = j; } } if (m != i) { swap(a, i, m); } } } }
private static long med3(final int[][] x, final long a, final long b, final long c, IntComparator comp) { int ab = comp.compare(get(x, a), get(x, b)); int ac = comp.compare(get(x, a), get(x, c)); int bc = comp.compare(get(x, b), get(x, c)); return (ab < 0 ? (bc < 0 ? b : ac < 0 ? c : a) : (bc > 0 ? b : ac > 0 ? c : a)); }
/** * Returns the element of the given big array of specified index. * * @param array a big array. * @param index a position in the big array. * @return the element of the big array at the specified position. */ public static int get(final int[][] array, final long index) { return array[segment(index)][displacement(index)]; }
private static void vecSwap(final int[][] x, long a, long b, final long n) { for (int i = 0; i < n; i++, a++, b++) { swap(x, a, b); } }
public void sort(int from, int to, IntComparator comparator) { IntBigArrays.quickSort(array, from, to, comparator); } }
/** * Returns the element of the given big array of specified index. * * @param array a big array. * @param index a position in the big array. * @return the element of the big array at the specified position. */ public static int get(final int[][] array, final long index) { return array[segment(index)][displacement(index)]; }
/** * Sets the element of the given big array of specified index. * * @param array a big array. * @param index a position in the big array. */ public static void set(final int[][] array, final long index, int value) { array[segment(index)][displacement(index)] = value; }
/** * Sets the element of the given big array of specified index. * * @param array a big array. * @param index a position in the big array. */ public static void set(final int[][] array, final long index, int value) { array[segment(index)][displacement(index)] = value; }
/** * Swaps the element of the given big array of specified indices. * * @param array a big array. * @param first a position in the big array. * @param second a position in the big array. */ public static void swap(final int[][] array, final long first, final long second) { final int t = array[segment(first)][displacement(first)]; array[segment(first)][displacement(first)] = array[segment(second)][displacement(second)]; array[segment(second)][displacement(second)] = t; }