org.apache.lucene.util

## Class IntroSorter

- java.lang.Object
- - org.apache.lucene.util.Sorter
  - - org.apache.lucene.util.IntroSorter

    public abstract class IntroSorter
    extends Sorter

`Sorter` implementation based on a variant of the quicksort algorithm called introsort: when the recursion level exceeds the log of the length of the array to sort, it falls back to heapsort. This prevents quicksort from running into its worst-case quadratic runtime. Small ranges are sorted with insertion sort.

This sort algorithm is fast on most data shapes, especially with low cardinality. If the data to sort is known to be strictly ascending or descending, prefer `TimSorter`.

NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.

### Constructor Summary

Constructors
Constructor and Description
`IntroSorter()` Create a new `IntroSorter`.

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods
`protected int` `compare(int i, int j)` Compare entries found in slots `i` and `j`.
`protected abstract int` `comparePivot(int j)` Compare the pivot with the slot at `j`, similarly to `compare(i, j)`.
`protected abstract void` `setPivot(int i)` Save the value at slot `i` so that it can later be used as a pivot, see `Sorter.comparePivot(int)`.
`void` `sort(int from, int to)` Sort the slice which starts at `from` (inclusive) and ends at `to` (exclusive).

### Methods inherited from class org.apache.lucene.util.Sorter

`swap`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### IntroSorter

    public IntroSorter()

Create a new `IntroSorter`.

### Method Detail

#### sort

    public final void sort(int from,
                           int to)

Description copied from class: `Sorter`
Sort the slice which starts at `from` (inclusive) and ends at `to` (exclusive).

Specified by:
  `sort` in class `Sorter`

#### setPivot

    protected abstract void setPivot(int i)

Description copied from class: `Sorter`
Save the value at slot `i` so that it can later be used as a pivot, see `Sorter.comparePivot(int)`.

Overrides:
  `setPivot` in class `Sorter`

#### comparePivot

    protected abstract int comparePivot(int j)

Description copied from class: `Sorter`
Compare the pivot with the slot at `j`, similarly to `compare(i, j)`.

Overrides:
  `comparePivot` in class `Sorter`

#### compare

    protected int compare(int i,
                          int j)

Description copied from class: `Sorter`
Compare entries found in slots `i` and `j`. The contract for the returned value is the same as `Comparator.compare(Object, Object)`.

Specified by:
  `compare` in class `Sorter`