presto-array/src/main/java/io/prestosql/array/IntBigArrays.java/IntBigArrays/quickSort
class IntBigArrays:    @SuppressWarnings("checkstyle:InnerAssignment")
    public static void quickSort(final int[][] x, final long from, final long to, final IntComparator comp)
    {
        final long len = to - from;
        // Selection sort on smallest arrays
        if (len < SMALL) {
            selectionSort(x, from, to, comp);
            return;
        }
        // Choose a partition element, v
        long m = from + len / 2; // Small arrays, middle element
        if (len > SMALL) {
            long l = from;
            long n = to - 1;
            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);
        // Establish Invariant: v* (<v)* (>v)* v*
        long a = from;
        long b = a;
        long c = to - 1;
        long d = c;
        while (true) {
            int comparison;
            while (b <= c && (comparison = comp.compare(get(x, b), v)) <= 0) {
                if (comparison == 0) {
                    swap(x, a++, b);
                }
                b++;
            }
            while (c >= b && (comparison = comp.compare(get(x, c), v)) >= 0) {
                if (comparison == 0) {
                    swap(x, c, d--);
                }
                c--;
            }
            if (b > c) {
                break;
            }
            swap(x, b++, c--);
        }
        // Swap partition elements back to middle
        long s;
        long n = to;
        s = Math.min(a - from, b - a);
        vecSwap(x, from, b - s, s);
        s = Math.min(d - c, n - d - 1);
        vecSwap(x, b, n - s, s);
        // Recursively sort non-partition-elements
        if ((s = b - a) > 1) {
            quickSort(x, from, from + s, comp);
        }
        if ((s = d - c) > 1) {
            quickSort(x, n - s, n, comp);
        }
    }