/** * Sorts the specified pair of arrays lexicographically using radix sort. * <p> * The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, * Keith Bostic and M. Douglas McIlroy, “Engineering radix sort”, * <i>Computing Systems</i>, 6(1), pages 5−27 (1993). * * <p> * This method implements a <em>lexicographical</em> sorting of the arguments. * Pairs of elements in the same position in the two provided arrays will be * considered a single key, and permuted accordingly. In the end, either * {@code a[i] < a[i + 1]} or {@code a[i] == a[i + 1]} and * {@code b[i] ≤ b[i + 1]}. * * @param a * the first array to be sorted. * @param b * the second array to be sorted. */ public static void radixSort(final int[] a, final int[] b) { ensureSameLength(a, b); radixSort(a, b, 0, a.length); } /**
/** * Sorts two arrays according to the natural lexicographical ascending order * using quicksort. * * <p> * The sorting algorithm is a tuned quicksort adapted from Jon L. Bentley and M. * Douglas McIlroy, “Engineering a Sort Function”, <i>Software: * Practice and Experience</i>, 23(11), pages 1249−1265, 1993. * * <p> * This method implements a <em>lexicographical</em> sorting of the arguments. * Pairs of elements in the same position in the two provided arrays will be * considered a single key, and permuted accordingly. In the end, either * {@code x[i] < x[i + 1]} or <code>x[i] * == x[i + 1]</code> and {@code y[i] ≤ y[i + 1]}. * * @param x * the first array to be sorted. * @param y * the second array to be sorted. */ public static void quickSort(final int[] x, final int[] y) { ensureSameLength(x, y); quickSort(x, y, 0, x.length); } protected static class ForkJoinQuickSort2 extends RecursiveAction {
/** * Sorts two arrays using a parallel radix sort. * * <p> * The sorting algorithm is a tuned radix sort adapted from Peter M. McIlroy, * Keith Bostic and M. Douglas McIlroy, “Engineering radix sort”, * <i>Computing Systems</i>, 6(1), pages 5−27 (1993). * * <p> * This method implements a <em>lexicographical</em> sorting of the arguments. * Pairs of elements in the same position in the two provided arrays will be * considered a single key, and permuted accordingly. In the end, either * {@code a[i] < a[i + 1]} or {@code a[i] == a[i + 1]} and * {@code b[i] ≤ b[i + 1]}. * * <p> * This implementation uses a pool of {@link Runtime#availableProcessors()} * threads. * * @param a * the first array to be sorted. * @param b * the second array to be sorted. */ public static void parallelRadixSort(final int[] a, final int[] b) { ensureSameLength(a, b); parallelRadixSort(a, b, 0, a.length); } private static void insertionSortIndirect(final int[] perm, final int[] a, final int[] b, final int from,
/** * Sorts two arrays according to the natural lexicographical ascending order * using a parallel quicksort. * * <p> * The sorting algorithm is a tuned quicksort adapted from Jon L. Bentley and M. * Douglas McIlroy, “Engineering a Sort Function”, <i>Software: * Practice and Experience</i>, 23(11), pages 1249−1265, 1993. * * <p> * This method implements a <em>lexicographical</em> sorting of the arguments. * Pairs of elements in the same position in the two provided arrays will be * considered a single key, and permuted accordingly. In the end, either * {@code x[i] < x[i + 1]} or <code>x[i] * == x[i + 1]</code> and {@code y[i] ≤ y[i + 1]}. * * <p> * This implementation uses a {@link ForkJoinPool} executor service with * {@link Runtime#availableProcessors()} parallel threads. * * @param x * the first array to be sorted. * @param y * the second array to be sorted. */ public static void parallelQuickSort(final int[] x, final int[] y) { ensureSameLength(x, y); parallelQuickSort(x, y, 0, x.length); } /**
ensureSameLength(a, b); radixSortIndirect(perm, a, b, 0, a.length, stable);