Class Sorter

  • Direct Known Subclasses:
    InPlaceMergeSorter, IntroSorter, MSBRadixSorter, TimSorter

    public abstract class Sorter
    extends Object
    Base class for sorting algorithms implementations.

    There are a number of subclasses to choose from that vary in performance and stability. We suggest that you pick the first from this ranked list that meets your requirements:

    1. MSBRadixSorter for strings (array of bytes/chars). Not a stable sort.
    2. StableMSBRadixSorter for strings (array of bytes/chars). Stable sort.
    3. IntroSorter. Not a stable sort.
    4. InPlaceMergeSorter. When the data to sort is typically small. Stable sort.
    5. TimSorter. Stable sort.
    NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
    • Constructor Detail

      • Sorter

        protected Sorter()
        Sole constructor, used for inheritance.
    • Method Detail

      • compare

        protected abstract int compare​(int i,
                                       int j)
        Compare entries found in slots i and j. The contract for the returned value is the same as, Object).
      • swap

        protected abstract void swap​(int i,
                                     int j)
        Swap values at slots i and j.
      • setPivot

        protected void setPivot​(int i)
        Save the value at slot i so that it can later be used as a pivot, see comparePivot(int).
      • comparePivot

        protected int comparePivot​(int j)
        Compare the pivot with the slot at j, similarly to compare(i, j).
      • sort

        public abstract void sort​(int from,
                                  int to)
        Sort the slice which starts at from (inclusive) and ends at to (exclusive).