Package org.apache.lucene.util
Class MSBRadixSorter
- java.lang.Object
-
- org.apache.lucene.util.Sorter
-
- org.apache.lucene.util.MSBRadixSorter
-
- Direct Known Subclasses:
StringMSBRadixSorter
public abstract class MSBRadixSorter extends Sorter
Radix sorter for variable-length strings. This class sorts based on the most significant byte first and falls back toIntroSorterwhen the size of the buckets to sort becomes small. It is NOT stable. Worst-case memory usage is about2.3 KB.
-
-
Field Summary
Fields Modifier and Type Field Description private int[]commonPrefixprivate int[]endOffsetsprivate static intHISTOGRAM_SIZEprivate int[][]histogramsprivate static intLENGTH_THRESHOLDprivate static intLEVEL_THRESHOLDprivate intmaxLength-
Fields inherited from class org.apache.lucene.util.Sorter
BINARY_SORT_THRESHOLD
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedMSBRadixSorter(int maxLength)Sole constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private booleanassertHistogram(int commonPrefixLength, int[] histogram)private voidbuildHistogram(int from, int to, int k, int[] histogram)Build an histogram of the k-th characters of values occurring between offsetsfromandto, usinggetBucket(int, int).protected abstract intbyteAt(int i, int k)Return the k-th byte of the entry at indexi, or-1if its length is less than or equal tok.protected intcompare(int i, int j)Compare entries found in slotsiandj.private intcomputeCommonPrefixLengthAndBuildHistogram(int from, int to, int k, int[] histogram)Build a histogram of the number of values perbucketand return a common prefix length for all visited values.private intgetBucket(int i, int k)Return a number for the k-th character between 0 andHISTOGRAM_SIZE.protected SortergetFallbackSorter(int k)Get a fall-back sorter which may assume that the first k bytes of all compared strings are equal.private voidintroSort(int from, int to, int k)private voidradixSort(int from, int to, int k, int l)private voidreorder(int from, int to, int[] startOffsets, int[] endOffsets, int k)Reorder based on start/end offsets for each bucket.voidsort(int from, int to)Sort the slice which starts atfrom(inclusive) and ends atto(exclusive).private voidsort(int from, int to, int k, int l)private static voidsumHistogram(int[] histogram, int[] endOffsets)Accumulate values of the histogram so that it does not store counts but start offsets.-
Methods inherited from class org.apache.lucene.util.Sorter
binarySort, binarySort, checkRange, comparePivot, doRotate, heapChild, heapify, heapParent, heapSort, lower, lower2, mergeInPlace, reverse, rotate, setPivot, siftDown, swap, upper, upper2
-
-
-
-
Field Detail
-
LEVEL_THRESHOLD
private static final int LEVEL_THRESHOLD
- See Also:
- Constant Field Values
-
HISTOGRAM_SIZE
private static final int HISTOGRAM_SIZE
- See Also:
- Constant Field Values
-
LENGTH_THRESHOLD
private static final int LENGTH_THRESHOLD
- See Also:
- Constant Field Values
-
histograms
private final int[][] histograms
-
endOffsets
private final int[] endOffsets
-
commonPrefix
private final int[] commonPrefix
-
maxLength
private final int maxLength
-
-
Method Detail
-
byteAt
protected abstract int byteAt(int i, int k)Return the k-th byte of the entry at indexi, or-1if its length is less than or equal tok. This may only be called with a value ofibetween0included andmaxLengthexcluded.
-
getFallbackSorter
protected Sorter getFallbackSorter(int k)
Get a fall-back sorter which may assume that the first k bytes of all compared strings are equal.
-
compare
protected final int compare(int i, int j)Description copied from class:SorterCompare entries found in slotsiandj. The contract for the returned value is the same asComparator.compare(Object, Object).
-
sort
public void sort(int from, int to)Description copied from class:SorterSort the slice which starts atfrom(inclusive) and ends atto(exclusive).
-
sort
private void sort(int from, int to, int k, int l)
-
introSort
private void introSort(int from, int to, int k)
-
radixSort
private void radixSort(int from, int to, int k, int l)- Parameters:
k- the character number to comparel- the level of recursion
-
assertHistogram
private boolean assertHistogram(int commonPrefixLength, int[] histogram)
-
getBucket
private int getBucket(int i, int k)Return a number for the k-th character between 0 andHISTOGRAM_SIZE.
-
computeCommonPrefixLengthAndBuildHistogram
private int computeCommonPrefixLengthAndBuildHistogram(int from, int to, int k, int[] histogram)Build a histogram of the number of values perbucketand return a common prefix length for all visited values.- See Also:
buildHistogram(int, int, int, int[])
-
buildHistogram
private void buildHistogram(int from, int to, int k, int[] histogram)Build an histogram of the k-th characters of values occurring between offsetsfromandto, usinggetBucket(int, int).
-
sumHistogram
private static void sumHistogram(int[] histogram, int[] endOffsets)Accumulate values of the histogram so that it does not store counts but start offsets.endOffsetswill store the end offsets.
-
reorder
private void reorder(int from, int to, int[] startOffsets, int[] endOffsets, int k)Reorder based on start/end offsets for each bucket. When this method returns, startOffsets and endOffsets are equal.- Parameters:
startOffsets- start offsets per bucketendOffsets- end offsets per bucket
-
-