Methods Summary |
---|
public final void | adjustTop()Should be called when the scorer at top changes doc() value.
Still log(n) worst case, but it's at least twice as fast to
{ pq.top().change(); pq.adjustTop(); }
instead of
{ o = pq.pop(); o.change(); pq.push(o); }
// assert size > 0;
topHSD.adjust();
downHeap();
|
private boolean | checkAdjustElsePop(boolean cond)
if (cond) { // see also adjustTop
topHSD.doc = topHSD.scorer.doc();
} else { // see also popNoResult
heap[1] = heap[size]; // move last to first
heap[size] = null;
size--;
}
downHeap();
return cond;
|
public final void | clear()Removes all entries from the ScorerDocQueue.
for (int i = 0; i <= size; i++) {
heap[i] = null;
}
size = 0;
|
private final void | downHeap()
int i = 1;
HeapedScorerDoc node = heap[i]; // save top node
int j = i << 1; // find smaller child
int k = j + 1;
if ((k <= size) && (heap[k].doc < heap[j].doc)) {
j = k;
}
while ((j <= size) && (heap[j].doc < node.doc)) {
heap[i] = heap[j]; // shift up child
i = j;
j = i << 1;
k = j + 1;
if (k <= size && (heap[k].doc < heap[j].doc)) {
j = k;
}
}
heap[i] = node; // install saved node
topHSD = heap[1];
|
public boolean | insert(org.apache.lucene.search.Scorer scorer)Adds a Scorer to the ScorerDocQueue in log(size) time if either
the ScorerDocQueue is not full, or not lessThan(scorer, top()).
if (size < maxSize) {
put(scorer);
return true;
} else {
int docNr = scorer.doc();
if ((size > 0) && (! (docNr < topHSD.doc))) { // heap[1] is top()
heap[1] = new HeapedScorerDoc(scorer, docNr);
downHeap();
return true;
} else {
return false;
}
}
|
public final org.apache.lucene.search.Scorer | pop()Removes and returns the least scorer of the ScorerDocQueue in log(size)
time.
Should not be used when the queue is empty.
// assert size > 0;
Scorer result = topHSD.scorer;
popNoResult();
return result;
|
private final void | popNoResult()Removes the least scorer of the ScorerDocQueue in log(size) time.
Should not be used when the queue is empty.
heap[1] = heap[size]; // move last to first
heap[size] = null;
size--;
downHeap(); // adjust heap
|
public final void | put(org.apache.lucene.search.Scorer scorer)Adds a Scorer to a ScorerDocQueue in log(size) time.
If one tries to add more Scorers than maxSize
a RuntimeException (ArrayIndexOutOfBound) is thrown.
size++;
heap[size] = new HeapedScorerDoc(scorer);
upHeap();
|
public final int | size()Returns the number of scorers currently stored in the ScorerDocQueue.
return size;
|
public final org.apache.lucene.search.Scorer | top()Returns the least Scorer of the ScorerDocQueue in constant time.
Should not be used when the queue is empty.
// assert size > 0;
return topHSD.scorer;
|
public final int | topDoc()Returns document number of the least Scorer of the ScorerDocQueue
in constant time.
Should not be used when the queue is empty.
// assert size > 0;
return topHSD.doc;
|
public final boolean | topNextAndAdjustElsePop()
return checkAdjustElsePop( topHSD.scorer.next());
|
public final float | topScore()
// assert size > 0;
return topHSD.scorer.score();
|
public final boolean | topSkipToAndAdjustElsePop(int target)
return checkAdjustElsePop( topHSD.scorer.skipTo(target));
|
private final void | upHeap()
int i = size;
HeapedScorerDoc node = heap[i]; // save bottom node
int j = i >>> 1;
while ((j > 0) && (node.doc < heap[j].doc)) {
heap[i] = heap[j]; // shift parents down
i = j;
j = j >>> 1;
}
heap[i] = node; // install saved node
topHSD = heap[1];
|