Add a comment about the recursion threshold of StringMSBRadixSorter.

This commit is contained in:
Adrien Grand 2016-05-26 09:49:27 +02:00
parent 94c7ccd589
commit 2554b10692
4 changed files with 7 additions and 4 deletions

View File

@ -33,7 +33,7 @@ public abstract class InPlaceMergeSorter extends Sorter {
} }
void mergeSort(int from, int to) { void mergeSort(int from, int to) {
if (to - from < THRESHOLD) { if (to - from < INSERTION_SORT_THRESHOLD) {
insertionSort(from, to); insertionSort(from, to);
} else { } else {
final int mid = (from + to) >>> 1; final int mid = (from + to) >>> 1;

View File

@ -38,7 +38,7 @@ public abstract class IntroSorter extends Sorter {
} }
void quicksort(int from, int to, int maxDepth) { void quicksort(int from, int to, int maxDepth) {
if (to - from < THRESHOLD) { if (to - from < INSERTION_SORT_THRESHOLD) {
insertionSort(from, to); insertionSort(from, to);
return; return;
} else if (--maxDepth < 0) { } else if (--maxDepth < 0) {

View File

@ -23,7 +23,7 @@ import java.util.Comparator;
* @lucene.internal */ * @lucene.internal */
public abstract class Sorter { public abstract class Sorter {
static final int THRESHOLD = 20; static final int INSERTION_SORT_THRESHOLD = 20;
/** Sole constructor, used for inheritance. */ /** Sole constructor, used for inheritance. */
protected Sorter() {} protected Sorter() {}

View File

@ -21,10 +21,13 @@ import java.util.Arrays;
/** Radix sorter for variable-length strings. This class sorts based on the most /** Radix sorter for variable-length strings. This class sorts based on the most
* significant byte first and falls back to {@link IntroSorter} when the size * significant byte first and falls back to {@link IntroSorter} when the size
* of the buckets to sort becomes small. It is <b>NOT</b> stable. * of the buckets to sort becomes small. It is <b>NOT</b> stable.
* Worst-case memory usage is about {@code 2.3 KB} */ * Worst-case memory usage is about {@code 2.3 KB}. */
abstract class StringMSBRadixSorter extends Sorter { abstract class StringMSBRadixSorter extends Sorter {
// after that many levels of recursion we fall back to introsort anyway // after that many levels of recursion we fall back to introsort anyway
// this is used as a protection against the fact that radix sort performs
// worse when there are long common prefixes (probably because of cache
// locality)
private static final int LEVEL_THRESHOLD = 8; private static final int LEVEL_THRESHOLD = 8;
// size of histograms: 256 + 1 to indicate that the string is finished // size of histograms: 256 + 1 to indicate that the string is finished
private static final int HISTOGRAM_SIZE = 257; private static final int HISTOGRAM_SIZE = 257;