Package org.drools.core.util
Class BinaryHeapQueue<T extends Queue.QueueEntry>
java.lang.Object
org.drools.core.util.BinaryHeapQueue<T>
- All Implemented Interfaces:
Externalizable,Serializable,Queue<T>
public class BinaryHeapQueue<T extends Queue.QueueEntry>
extends Object
implements Queue<T>, Externalizable
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.drools.core.util.Queue
Queue.QueueEntry -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionBinaryHeapQueue(Comparator<T> comparator) Constructs a newBinaryHeapthat will use the given comparator to order its elements.BinaryHeapQueue(Comparator<T> comparator, int capacity) Constructs a newBinaryHeap. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears all elements from queue.dequeue()Returns the Queueable on top of heap and remove it.voidvoidInserts an Queueable into queue.getAll()booleanisEmpty()Tests if queue is empty.booleanisFull()Tests if queue is full.peek()protected voidpercolateDownMaxHeap(int index) Percolates element down heap from the position given by the index.protected voidpercolateUpMaxHeap(int index) Percolates element up heap from the position given by the index.protected voidpercolateUpMaxHeap(T element) Percolates a new element up heap from the bottom.voidintsize()Returns the number of elements in this heap.toString()void
-
Field Details
-
log
protected static final transient org.slf4j.Logger log
-
-
Constructor Details
-
BinaryHeapQueue
public BinaryHeapQueue() -
BinaryHeapQueue
Constructs a newBinaryHeapthat will use the given comparator to order its elements.- Parameters:
comparator- the comparator used to order the elements, null means use natural order
-
BinaryHeapQueue
Constructs a newBinaryHeap.- Parameters:
comparator- the comparator used to order the elements, null means use natural ordercapacity- the initial capacity for the heap- Throws:
IllegalArgumentException- ifcapacityis <=0
-
-
Method Details
-
readExternal
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
writeExternal
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
clear
public void clear()Clears all elements from queue.- Specified by:
clearin interfaceQueue<T extends Queue.QueueEntry>
-
isEmpty
public boolean isEmpty()Tests if queue is empty.- Specified by:
isEmptyin interfaceQueue<T extends Queue.QueueEntry>- Returns:
trueif queue is empty;falseotherwise.
-
isFull
public boolean isFull()Tests if queue is full.- Returns:
trueif queue is full;falseotherwise.
-
size
public int size()Returns the number of elements in this heap.- Specified by:
sizein interfaceQueue<T extends Queue.QueueEntry>- Returns:
- the number of elements in this heap
-
peek
- Specified by:
peekin interfaceQueue<T extends Queue.QueueEntry>
-
enqueue
Inserts an Queueable into queue.- Specified by:
enqueuein interfaceQueue<T extends Queue.QueueEntry>- Parameters:
element- the Queueable to be inserted
-
dequeue
Returns the Queueable on top of heap and remove it.- Specified by:
dequeuein interfaceQueue<T extends Queue.QueueEntry>- Returns:
- the Queueable at top of heap
- Throws:
NoSuchElementException- ifisEmpty() == true
-
dequeue
- Specified by:
dequeuein interfaceQueue<T extends Queue.QueueEntry>
-
percolateDownMaxHeap
protected void percolateDownMaxHeap(int index) Percolates element down heap from the position given by the index.Assumes it is a maximum heap.
- Parameters:
index- the index of the element
-
percolateUpMaxHeap
protected void percolateUpMaxHeap(int index) Percolates element up heap from the position given by the index.Assume it is a maximum heap.
- Parameters:
index- the index of the element to be percolated up
-
percolateUpMaxHeap
Percolates a new element up heap from the bottom.Assume it is a maximum heap.
- Parameters:
element- the element
-
getAll
- Specified by:
getAllin interfaceQueue<T extends Queue.QueueEntry>
-
toString
-