Package org.apache.solr.util
Class LongPriorityQueue
- java.lang.Object
-
- org.apache.solr.util.LongPriorityQueue
-
public class LongPriorityQueue extends Object
A native long priority queue.- NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
-
-
Field Summary
Fields Modifier and Type Field Description protected intcurrentCapacityprotected long[]heapprotected intmaxSizeprotected longsentinelprotected intsize
-
Constructor Summary
Constructors Constructor Description LongPriorityQueue(int initialSize, int maxSize, long sentinel)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longadd(long element)Adds an object to a PriorityQueue in log(size) time.voidaddNoCheck(long element)Adds an object to a PriorityQueue in log(size) time.voidclear()Removes all entries from the PriorityQueue.intgetCurrentCapacity()long[]getInternalArray()Returns the array used to hold the heap, with the smallest item at array[1] and the last (but not necessarily largest) at array[size()].protected voidinitialize(int sz)booleaninsert(long element)inserts the element and returns true if this element caused another element to be dropped from the queue.longinsertWithOverflow(long element)Adds an object to a PriorityQueue in log(size) time.longpop()Removes and returns the least element of the PriorityQueue in log(size) time.voidresize(int sz)intsize()Returns the number of elements currently stored in the PriorityQueue.long[]sort(int n)Pops the smallest n items from the heap, placing them in the internal array at arr[size] through arr[size-(n-1)] with the smallest (first element popped) being at arr[size].longtop()Returns the least element of the PriorityQueue in constant time.longupdateTop()Should be called when the Object at top changes values.
-
-
-
Method Detail
-
initialize
protected void initialize(int sz)
-
getCurrentCapacity
public int getCurrentCapacity()
-
resize
public void resize(int sz)
-
add
public long add(long element)
Adds an object to a PriorityQueue in log(size) time. If one tries to add more objects than maxSize from initialize anArrayIndexOutOfBoundsExceptionis thrown.- Returns:
- the new 'top' element in the queue.
-
addNoCheck
public void addNoCheck(long element)
Adds an object to a PriorityQueue in log(size) time. If one tries to add more objects than the current capacity, anArrayIndexOutOfBoundsExceptionis thrown.
-
insertWithOverflow
public long insertWithOverflow(long element)
Adds an object to a PriorityQueue in log(size) time. It returns the smallest object (if any) that was dropped off the heap because it was full, or the sentinel value.This can be the given parameter (in case it is smaller than the full heap's minimum, and couldn't be added), or another object that was previously the smallest value in the heap and now has been replaced by a larger one, or null if the queue wasn't yet full with maxSize elements.
-
insert
public boolean insert(long element)
inserts the element and returns true if this element caused another element to be dropped from the queue.
-
top
public long top()
Returns the least element of the PriorityQueue in constant time.
-
pop
public long pop()
Removes and returns the least element of the PriorityQueue in log(size) time. Only valid if size() > 0.
-
updateTop
public long updateTop()
Should be called when the Object at top changes values.- Returns:
- the new 'top' element.
-
size
public int size()
Returns the number of elements currently stored in the PriorityQueue.
-
getInternalArray
public long[] getInternalArray()
Returns the array used to hold the heap, with the smallest item at array[1] and the last (but not necessarily largest) at array[size()]. This is *not* fully sorted.
-
sort
public long[] sort(int n)
Pops the smallest n items from the heap, placing them in the internal array at arr[size] through arr[size-(n-1)] with the smallest (first element popped) being at arr[size]. The internal array is returned.
-
clear
public void clear()
Removes all entries from the PriorityQueue.
-
-