final void updateBottom(int doc) { // bottom.score is already set to Float.NaN in add(). bottom.doc = docBase + doc; bottom = pq.updateTop(); }
final void updateBottom(int doc, float score) { bottom.doc = docBase + doc; bottom.score = score; bottom = pq.updateTop(); }
/** * Replace the top of the pq with {@code newTop} and run {@link #updateTop()}. */ public final T updateTop(T newTop) { heap[1] = newTop; return updateTop(); }
@Override public void collect(int doc) throws IOException { float score = scorer.score(); // This collector cannot handle these scores: assert score != Float.NEGATIVE_INFINITY; assert !Float.isNaN(score); totalHits++; if (score <= pqTop.score) { // Since docs are returned in-order (i.e., increasing doc Id), a document // with equal score to pqTop.score cannot compete since HitQueue favors // documents with lower doc Ids. Therefore reject those docs too. return; } pqTop.doc = doc + docBase; pqTop.score = score; pqTop = pq.updateTop(); }
@Override public void collect(int doc) throws IOException { float score = scorer.score(); // This collector cannot handle these scores: assert score != Float.NEGATIVE_INFINITY; assert !Float.isNaN(score); totalHits++; if (score > after.score || (score == after.score && doc <= afterDoc)) { // hit was collected on a previous page return; } if (score <= pqTop.score) { // Since docs are returned in-order (i.e., increasing doc Id), a document // with equal score to pqTop.score cannot compete since HitQueue favors // documents with lower doc Ids. Therefore reject those docs too. return; } collectedHits++; pqTop.doc = doc + docBase; pqTop.score = score; pqTop = pq.updateTop(); } };
/** * Adds an Object to a PriorityQueue in log(size) time. * It returns the object (if any) that was * dropped off the heap because it was full. This can be * the given parameter (in case it is smaller than the * full heap's minimum, and couldn't be added), or another * object that was previously the smallest value in the * heap and now has been replaced by a larger one, or null * if the queue wasn't yet full with maxSize elements. */ public T insertWithOverflow(T element) { if (size < maxSize) { add(element); return null; } else if (size > 0 && !lessThan(element, heap[1])) { T ret = heap[1]; heap[1] = element; updateTop(); return ret; } else { return element; } }
@Override public boolean next() throws IOException { if (started == false) { return started = true; } if (queue.top().next() == false) { queue.pop(); } if (queue.size() > 0) { queue.updateTop(); return true; } return false; }
@Override public T next() throws IOException { T top = queue.top(); while (true) { int docID = top.nextDoc(); if (docID == NO_MORE_DOCS) { queue.pop(); top = queue.top(); break; } int mappedDocID = top.docMap.get(docID); if (mappedDocID == -1) { // doc was deleted continue; } else { top.mappedDocID = mappedDocID; top = queue.updateTop(); break; } } return top; } }
queue.updateTop(); } else { queue.pop();
@Override public int nextDoc() { // Advance all sub iterators past current doc while (true) { if (queue.size() == 0) { doc = NO_MORE_DOCS; break; } int newDoc = queue.top().docID(); if (newDoc != doc) { assert newDoc > doc: "doc=" + doc + " newDoc=" + newDoc; doc = newDoc; break; } if (queue.top().nextDoc() == NO_MORE_DOCS) { queue.pop(); } else { queue.updateTop(); } } return doc; }
queue.updateTop(); } else { queue.pop();
@Override public int nextPosition() throws IOException { if (started == false) { started = true; return posQueue.top().pos; } if (posQueue.top().upto == 1) { posQueue.pop(); return posQueue.top().pos; } posQueue.top().pos = posQueue.top().pe.nextPosition(); posQueue.top().upto--; posQueue.updateTop(); return posQueue.top().pos; }
assert top.values[j] != null; queue.updateTop(); } else { queue.pop();
private void updateTop(CandidateSet[] candidates, Candidate[] path, PriorityQueue<Correction> corrections, double cutoffScore, double score) throws IOException { score = Math.exp(score); assert Math.abs(score - score(path, candidates)) < 0.00001; if (score > cutoffScore) { if (corrections.size() < maxNumCorrections) { Candidate[] c = new Candidate[candidates.length]; System.arraycopy(path, 0, c, 0, path.length); corrections.add(new Correction(score, c)); } else if (corrections.top().compareTo(score, path) < 0) { Correction top = corrections.top(); System.arraycopy(path, 0, top.candidates, 0, path.length); top.score = score; corrections.updateTop(); } } }
assert next.key > top.current.key : "shards must return data sorted by key"; top.current = next; pq.updateTop(); } else { pq.pop();
assert Double.compare(next.key, top.current.key) > 0 : "shards must return data sorted by key"; top.current = next; pq.updateTop(); } else { pq.pop();
assert next.key > top.current.key : "shards must return data sorted by key"; top.current = next; pq.updateTop(); } else { pq.pop();
/** * Replace the top of the pq with {@code newTop} and run {@link #updateTop()}. */ public final T updateTop(T newTop) { heap[1] = newTop; return updateTop(); }