Class FastUtilArrays
In addition to commodity methods, this class contains {link it.unimi.dsi.fastutil.Swapper}-based implementations of quickSort(int, int, Comparator, Swapper) quicksort} These generic sorting methods can be used to sort any kind of list, but they find their natural usage, for instance, in sorting arrays in parallel.
Some algorithms provide a parallel version that will by default use the
common pool, but this can be overridden by calling the
function in a task already in the ForkJoinPool that the operation should run in. For example,
something along the lines of "poolToParallelSortIn.invoke(() -> parallelQuickSort(arrayToSort))"
will run the parallel sort in poolToParallelSortIn instead of the default pool.
see Arrays
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidquickSort(int from, int to, Comparator comp, Swapper swapper) Sorts the specified range of elements using the specified swapper and according to the order induced by the specified comparator using parallel quicksort.protected static voidSwaps two sequences of elements using a provided swapper.
-
Constructor Details
-
FastUtilArrays
public FastUtilArrays()
-
-
Method Details
-
swap
Swaps two sequences of elements using a provided swapper.- Parameters:
swapper- the swapper.a- a position inx.b- another position inx.n- the number of elements to exchange starting ataandb.
-
quickSort
Sorts the specified range of elements using the specified swapper and according to the order induced by the specified comparator using parallel quicksort.The sorting algorithm is a tuned quicksort adapted from Jon L. Bentley and M. Douglas McIlroy, “Engineering a Sort Function”, Software: Practice and Experience, 23(11), pages 1249−1265, 1993.
- Parameters:
from- the index of the first element (inclusive) to be sorted.to- the index of the last element (exclusive) to be sorted.comp- the comparator to determine the order of the generic data.swapper- an object that knows how to swap the elements at any two positions.
-