22
22
* A ternary min heap that stores longs; a primitive priority queue that like all priority queues
23
23
* maintains a partial ordering of its elements such that the least element can always be found in
24
24
* 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
26
26
* #insertWithOverflow(long)}. The heap is a min heap, meaning that the top element is the lowest
27
27
* value of the heap. TernaryLongHeap implements 3-ary heap.
28
28
*
29
29
* @lucene.internal
30
30
*/
31
31
public final class TernaryLongHeap {
32
32
33
- private final int maxSize ;
33
+ private final int initialCapacity ;
34
34
35
35
private long [] heap ;
36
36
private int size = 0 ;
@@ -51,18 +51,17 @@ public TernaryLongHeap(int size, long initialValue) {
51
51
/**
52
52
* Create an empty priority queue of the configured initial size.
53
53
*
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
56
55
*/
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 ) {
59
58
// Throw exception to prevent confusing OOME:
60
59
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 );
62
61
}
63
62
// 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 ;
66
65
this .heap = new long [heapSize ];
67
66
}
68
67
@@ -83,13 +82,13 @@ public long push(long element) {
83
82
84
83
/**
85
84
* 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.
87
86
*
88
87
* @return whether the value was added (unless the heap is full, or the new value is less than the
89
88
* top value)
90
89
*/
91
90
public boolean insertWithOverflow (long value ) {
92
- if (size >= maxSize ) {
91
+ if (size >= initialCapacity ) {
93
92
if (value < heap [1 ]) {
94
93
return false ;
95
94
}
0 commit comments