mirror of https://github.com/apache/lucene.git
LUCENE-3023: Fix quicksort re-incarnation
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1098592 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fda913a790
commit
744840f141
|
@ -19,6 +19,7 @@ package org.apache.lucene.index;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -26,6 +27,7 @@ import java.util.Map;
|
|||
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.util.ArrayUtil;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -232,7 +234,7 @@ final class DocFieldProcessor extends DocConsumer {
|
|||
// sort the subset of fields that have vectors
|
||||
// enabled; we could save [small amount of] CPU
|
||||
// here.
|
||||
quickSort(fields, 0, fieldCount-1);
|
||||
ArrayUtil.quickSort(fields, 0, fieldCount, fieldsComp);
|
||||
|
||||
for(int i=0;i<fieldCount;i++)
|
||||
fields[i].consumer.processFields(fields[i].fields, fields[i].fieldCount);
|
||||
|
@ -243,6 +245,12 @@ final class DocFieldProcessor extends DocConsumer {
|
|||
}
|
||||
}
|
||||
|
||||
private static final Comparator<DocFieldProcessorPerField> fieldsComp = new Comparator<DocFieldProcessorPerField>() {
|
||||
public int compare(DocFieldProcessorPerField o1, DocFieldProcessorPerField o2) {
|
||||
return o1.fieldInfo.name.compareTo(o2.fieldInfo.name);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
void finishDocument() throws IOException {
|
||||
try {
|
||||
|
@ -252,64 +260,4 @@ final class DocFieldProcessor extends DocConsumer {
|
|||
}
|
||||
}
|
||||
|
||||
void quickSort(DocFieldProcessorPerField[] array, int lo, int hi) {
|
||||
if (lo >= hi)
|
||||
return;
|
||||
else if (hi == 1+lo) {
|
||||
if (array[lo].fieldInfo.name.compareTo(array[hi].fieldInfo.name) > 0) {
|
||||
final DocFieldProcessorPerField tmp = array[lo];
|
||||
array[lo] = array[hi];
|
||||
array[hi] = tmp;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int mid = (lo + hi) >>> 1;
|
||||
|
||||
if (array[lo].fieldInfo.name.compareTo(array[mid].fieldInfo.name) > 0) {
|
||||
DocFieldProcessorPerField tmp = array[lo];
|
||||
array[lo] = array[mid];
|
||||
array[mid] = tmp;
|
||||
}
|
||||
|
||||
if (array[mid].fieldInfo.name.compareTo(array[hi].fieldInfo.name) > 0) {
|
||||
DocFieldProcessorPerField tmp = array[mid];
|
||||
array[mid] = array[hi];
|
||||
array[hi] = tmp;
|
||||
|
||||
if (array[lo].fieldInfo.name.compareTo(array[mid].fieldInfo.name) > 0) {
|
||||
DocFieldProcessorPerField tmp2 = array[lo];
|
||||
array[lo] = array[mid];
|
||||
array[mid] = tmp2;
|
||||
}
|
||||
}
|
||||
|
||||
int left = lo + 1;
|
||||
int right = hi - 1;
|
||||
|
||||
if (left >= right)
|
||||
return;
|
||||
|
||||
DocFieldProcessorPerField partition = array[mid];
|
||||
|
||||
for (; ;) {
|
||||
while (array[right].fieldInfo.name.compareTo(partition.fieldInfo.name) > 0)
|
||||
--right;
|
||||
|
||||
while (left < right && array[left].fieldInfo.name.compareTo(partition.fieldInfo.name) <= 0)
|
||||
++left;
|
||||
|
||||
if (left < right) {
|
||||
DocFieldProcessorPerField tmp = array[left];
|
||||
array[left] = array[right];
|
||||
array[right] = tmp;
|
||||
--right;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
quickSort(array, lo, left);
|
||||
quickSort(array, left + 1, hi);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue