private final void upHeap() { int i = size; final HeapedScorerNode node = heap[i]; // save bottom node int j = i >>> 1; while ((j > 0) && (this.compareTo(node.scorer, heap[j].scorer) < 0)) { heap[i] = heap[j]; // shift parents down i = j; j = j >>> 1; } heap[i] = node; // install saved node topHSN = heap[1]; }
private final void downHeap() { int i = 1; final HeapedScorerNode node = heap[i]; // save top node int j = i << 1; // find smaller child int k = j + 1; if ((k <= size) && (this.compareTo(heap[k].scorer, heap[j].scorer) < 0)) { j = k; } while ((j <= size) && (this.compareTo(heap[j].scorer, node.scorer) < 0)) { heap[i] = heap[j]; // shift up child i = j; j = i << 1; k = j + 1; if (k <= size && (this.compareTo(heap[k].scorer, heap[j].scorer) < 0)) { j = k; } } heap[i] = node; // install saved node topHSN = heap[1]; }