Skip to content

Commit 2fc2a61

Browse files
rename maxSize to initialCapacity in LongHeap and TernaryLongHeap
1 parent ff1ea3e commit 2fc2a61

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

lucene/core/src/java/org/apache/lucene/util/LongHeap.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
* A min heap that stores longs; a primitive priority queue that like all priority queues maintains
2323
* a partial ordering of its elements such that the least element can always be found in constant
2424
* time. Put()'s and pop()'s require log(size). This heap provides unbounded growth via {@link
25-
* #push(long)}, and bounded-size insertion based on its nominal maxSize via {@link
25+
* #push(long)}, and bounded-size insertion based on its 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. LongHeap implements 2-ary heap.
2828
*
2929
* @lucene.internal
3030
*/
3131
public final class LongHeap {
3232

33-
private final int maxSize;
33+
private final int initialCapacity;
3434

3535
private long[] heap;
3636
private int size = 0;
@@ -50,19 +50,18 @@ public LongHeap(int size, long initialValue) {
5050
/**
5151
* Create an empty priority queue of the configured initial size.
5252
*
53-
* @param maxSize the maximum size of the heap, or if negative, the initial size of an unbounded
54-
* heap
53+
* @param initialCapacity the initial capacity of the heap
5554
*/
56-
public LongHeap(int maxSize) {
55+
public LongHeap(int initialCapacity) {
5756
final int heapSize;
58-
if (maxSize < 1 || maxSize >= ArrayUtil.MAX_ARRAY_LENGTH) {
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-
heapSize = maxSize + 1;
65-
this.maxSize = maxSize;
63+
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 LongHeap in log(size) time. If the number of values would exceed the heap's
86-
* maxSize, the least value is discarded.
85+
* 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
}

lucene/core/src/java/org/apache/lucene/util/TernaryLongHeap.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
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
*/
3131
public 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

Comments
 (0)