Package org.apache.lucene.util
Class MSBRadixSorter
- java.lang.Object
-
- org.apache.lucene.util.Sorter
-
- org.apache.lucene.util.MSBRadixSorter
-
- Direct Known Subclasses:
StableMSBRadixSorter,StringSorter.MSBStringRadixSorter
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.This algorithm is NOT stable. Worst-case memory usage is about
2.3 KB.- NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
-
-
Field Summary
Fields Modifier and Type Field Description protected static intHISTOGRAM_SIZEprotected static intLENGTH_THRESHOLDprotected static intLEVEL_THRESHOLDprotected intmaxLength
-
Constructor Summary
Constructors Modifier Constructor Description protectedMSBRadixSorter(int maxLength)Sole constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidbuildHistogram(int prefixCommonBucket, int prefixCommonLen, 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.protected 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.protected voidreorder(int from, int to, int[] startOffsets, int[] endOffsets, int k)Reorder based on start/end offsets for each bucket.protected booleanshouldFallback(int from, int to, int l)voidsort(int from, int to)Sort the slice which starts atfrom(inclusive) and ends atto(exclusive).protected voidsort(int from, int to, int k, int l)-
Methods inherited from class org.apache.lucene.util.Sorter
comparePivot, setPivot, swap
-
-
-
-
Field Detail
-
LEVEL_THRESHOLD
protected static final int LEVEL_THRESHOLD
- See Also:
- Constant Field Values
-
HISTOGRAM_SIZE
protected static final int HISTOGRAM_SIZE
- See Also:
- Constant Field Values
-
LENGTH_THRESHOLD
protected static final int LENGTH_THRESHOLD
- See Also:
- Constant Field Values
-
maxLength
protected final int maxLength
-
-
Constructor Detail
-
MSBRadixSorter
protected MSBRadixSorter(int maxLength)
Sole constructor.- Parameters:
maxLength- the maximum length of keys, passInteger.MAX_VALUEif unknown.
-
-
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
protected void sort(int from, int to, int k, int l)
-
shouldFallback
protected boolean shouldFallback(int from, int to, int l)
-
getBucket
protected int getBucket(int i, int k)Return a number for the k-th character between 0 andHISTOGRAM_SIZE.
-
buildHistogram
protected void buildHistogram(int prefixCommonBucket, int prefixCommonLen, int from, int to, int k, int[] histogram)Build an histogram of the k-th characters of values occurring between offsetsfromandto, usinggetBucket(int, int).
-
reorder
protected 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
-
-