2222 * A ternary min heap that stores longs; a primitive priority queue that like all priority queues
2323 * maintains a partial ordering of its elements such that the least element can always be found in
2424 * constant time. Put()'s and pop()'s require log_3(size). This heap provides unbounded growth via
25- * {@link #push(long)}, and bounded-size insertion based on its nominal maxSize via {@link
25+ * {@link #push(long)}, and bounded-size insertion based on its nominal initial capacity via {@link
2626 * #insertWithOverflow(long)}. The heap is a min heap, meaning that the top element is the lowest
2727 * value of the heap. TernaryLongHeap implements 3-ary heap.
2828 *
2929 * @lucene.internal
3030 */
3131public final class TernaryLongHeap {
3232
33- private final int maxSize ;
33+ private final int initialCapacity ;
3434
3535 private long [] heap ;
3636 private int size = 0 ;
@@ -51,18 +51,17 @@ public TernaryLongHeap(int size, long initialValue) {
5151 /**
5252 * Create an empty priority queue of the configured initial size.
5353 *
54- * @param maxSize the maximum size of the heap, or if negative, the initial size of an unbounded
55- * heap
54+ * @param initialCapacity the initial capacity of the heap
5655 */
57- public TernaryLongHeap (int maxSize ) {
58- if (maxSize < 1 || maxSize >= ArrayUtil .MAX_ARRAY_LENGTH ) {
56+ public TernaryLongHeap (int initialCapacity ) {
57+ if (initialCapacity < 1 || initialCapacity >= ArrayUtil .MAX_ARRAY_LENGTH ) {
5958 // Throw exception to prevent confusing OOME:
6059 throw new IllegalArgumentException (
61- "maxSize must be > 0 and < " + (ArrayUtil .MAX_ARRAY_LENGTH - 1 ) + "; got: " + maxSize );
60+ "initialCapacity must be > 0 and < " + (ArrayUtil .MAX_ARRAY_LENGTH - 1 ) + "; got: " + initialCapacity );
6261 }
6362 // NOTE: we add +1 because all access to heap is 1-based not 0-based. heap[0] is unused.
64- final int heapSize = maxSize + 1 ;
65- this .maxSize = maxSize ;
63+ final int heapSize = initialCapacity + 1 ;
64+ this .initialCapacity = initialCapacity ;
6665 this .heap = new long [heapSize ];
6766 }
6867
@@ -83,13 +82,13 @@ public long push(long element) {
8382
8483 /**
8584 * Adds a value to an TernaryLongHeap in log(size) time. If the number of values would exceed the
86- * heap's maxSize , the least value is discarded.
85+ * heap's initialCapacity , the least value is discarded.
8786 *
8887 * @return whether the value was added (unless the heap is full, or the new value is less than the
8988 * top value)
9089 */
9190 public boolean insertWithOverflow (long value ) {
92- if (size >= maxSize ) {
91+ if (size >= initialCapacity ) {
9392 if (value < heap [1 ]) {
9493 return false ;
9594 }
0 commit comments