Class FastUtilArrays

java.lang.Object
emi.shims.java.it.unimi.dsi.fasttutil.FastUtilArrays

public class FastUtilArrays extends Object
A class providing static methods and objects that do useful things with arrays.

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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    quickSort(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 void
    swap(Swapper swapper, int a, int b, int n)
    Swaps two sequences of elements using a provided swapper.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • FastUtilArrays

      public FastUtilArrays()
  • Method Details

    • swap

      protected static void swap(Swapper swapper, int a, int b, int n)
      Swaps two sequences of elements using a provided swapper.
      Parameters:
      swapper - the swapper.
      a - a position in x.
      b - another position in x.
      n - the number of elements to exchange starting at a and b.
    • quickSort

      public static void quickSort(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.

      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.