static void sortWith0(int[] a, int fromIndex, int toIndex, IntComparator cmp) {
        final int length = toIndex - fromIndex + 1;
        if (length < 2)
            return;
        if (length == 2) {
            if (cmp.gt(a[fromIndex], a[toIndex])) {
                int x = a[fromIndex];
                a[fromIndex] = a[toIndex];
                a[toIndex] = x;
            }
            return;
        }
        // FIXME bad performance
        final int pivot = a[fromIndex];
        int p1 = 0;
        int p2 = 0;
        int[] a1 = new int[length];
        int[] a2 = new int[length];
        for (int i = fromIndex + 1; i <= toIndex; i++) {
            final int v = a[i];
            if (cmp.lt(v, pivot))
                a1[p1++] = v;
            else
                a2[p2++] = v;
        }
        int p = fromIndex;
        for (int i = 0; i < p1; i++)
            a[p++] = a1[i];
        a[p++] = pivot;
        for (int i = 0; i < p2; i++)
            a[p++] = a2[i];
        if (p1 > 0)
            sortWith0(a, fromIndex, fromIndex + p1 - 1, cmp);
        if (p2 > 0)
            sortWith0(a, fromIndex + p1 + 1, toIndex, cmp);
    }