Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

- Fixed clear() method that wasn't setting the very last heap element to null, as reported at http://nagoya.apache.org/bugzilla/show_bug.cgi?id=9454. PR: 9454 Obtained from: Submitted by: Reviewed by:

Otis Gospodnetica7bd647dd6c9
diff --git a/src/java/org/apache/lucene/util/PriorityQueue.java b/src/java/org/apache/lucene/util/PriorityQueue.java
index f97d0af6a2f..9cae158b802 100644
--- a/src/java/org/apache/lucene/util/PriorityQueue.java
+++ b/src/java/org/apache/lucene/util/PriorityQueue.java
@@ -72,9 +72,9 @@ public abstract class PriorityQueue {
heap = new Object[heapSize];
}
- /** Adds an Object to a PriorityQueue in log(size) time. */
+ /** Adds an Object to a PriorityQueue in log(size) time. */
public final void put(Object element) {
- size++;
+ size++;
heap[size] = element;
upHeap();
}
@@ -88,7 +88,7 @@ public abstract class PriorityQueue {
}
/** Removes and returns the least element of the PriorityQueue in log(size)
- time. */
+ time. */
public final Object pop() {
if (size > 0) {
Object result = heap[1]; // save first value
@@ -111,16 +111,16 @@ public abstract class PriorityQueue {
public final void adjustTop() {
downHeap();
}
-
+
/** Returns the number of elements currently stored in the PriorityQueue. */
public final int size() {
return size;
}
-
+
/** Removes all entries from the PriorityQueue. */
public final void clear() {
- for (int i = 0; i < size; i++)
+ for (int i = 0; i <= size; i++)
heap[i] = null;
size = 0;
}
@@ -136,7 +136,7 @@ public abstract class PriorityQueue {
}
heap[i] = node; // install saved node
}
-
+
private final void downHeap() {
int i = 1;
Object node = heap[i]; // save top node