don't don binary search in two places

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4547@1433362 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2013-01-15 11:48:42 +00:00
parent 09d19ac341
commit 1e29841a26
1 changed files with 14 additions and 21 deletions

View File

@ -52,30 +52,23 @@ public abstract class SortedDocValues extends BinaryDocValues {
@Override @Override
public SeekStatus seekCeil(BytesRef text, boolean useCache /* ignored */) throws IOException { public SeekStatus seekCeil(BytesRef text, boolean useCache /* ignored */) throws IOException {
int low = 0; int ord = lookupTerm(text, term);
int high = getValueCount()-1; if (ord > 0) {
currentOrd = ord;
while (low <= high) { term.offset = 0;
int mid = (low + high) >>> 1; term.copyBytes(text);
seekExact(mid); return SeekStatus.FOUND;
int cmp = term.compareTo(text); } else {
currentOrd = -ord-1;
if (cmp < 0) if (currentOrd == getValueCount()) {
low = mid + 1;
else if (cmp > 0)
high = mid - 1;
else {
return SeekStatus.FOUND; // key found
}
}
if (low == getValueCount()) {
return SeekStatus.END; return SeekStatus.END;
} else { } else {
seekExact(low); // nocommit hmm can we avoid this "extra" lookup?:
lookupOrd(currentOrd, term);
return SeekStatus.NOT_FOUND; return SeekStatus.NOT_FOUND;
} }
} }
}
@Override @Override
public void seekExact(long ord) throws IOException { public void seekExact(long ord) throws IOException {