Package org.drools.core.util
Class BinaryHeapQueue
- java.lang.Object
-
- org.drools.core.util.BinaryHeapQueue
-
- All Implemented Interfaces:
Externalizable,Serializable,Queue
public class BinaryHeapQueue extends Object implements Queue, Externalizable
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.slf4j.Loggerlog
-
Constructor Summary
Constructors Constructor Description BinaryHeapQueue()BinaryHeapQueue(Comparator<Activation> comparator)Constructs a newBinaryHeapthat will use the given comparator to order its elements.BinaryHeapQueue(Comparator<Activation> comparator, int capacity)Constructs a newBinaryHeap.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears all elements from queue.Activationdequeue()Returns the Queueable on top of heap and remove it.voiddequeue(Activation activation)voidenqueue(Activation element)Inserts an Queueable into queue.Activation[]getAndClear()booleanisEmpty()Tests if queue is empty.booleanisFull()Tests if queue is full.Activationpeek()protected voidpercolateDownMaxHeap(int index)Percolates element down heap from the position given by the index.protected voidpercolateUpMaxHeap(int index)Percolates element up heap from from the position given by the index.protected voidpercolateUpMaxHeap(Activation element)Percolates a new element up heap from the bottom.voidreadExternal(ObjectInput in)intsize()Returns the number of elements in this heap.Object[]toArray(Object[] a)StringtoString()voidwriteExternal(ObjectOutput out)
-
-
-
Constructor Detail
-
BinaryHeapQueue
public BinaryHeapQueue()
-
BinaryHeapQueue
public BinaryHeapQueue(Comparator<Activation> comparator)
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
public BinaryHeapQueue(Comparator<Activation> comparator, int capacity)
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 Detail
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
getAndClear
public Activation[] getAndClear()
- Specified by:
getAndClearin interfaceQueue
-
isEmpty
public boolean isEmpty()
Tests if queue is empty.
-
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.
-
peek
public Activation peek()
-
enqueue
public void enqueue(Activation element)
Inserts an Queueable into queue.
-
dequeue
public Activation dequeue()
Returns the Queueable on top of heap and remove it.- Specified by:
dequeuein interfaceQueue- Returns:
- the Queueable at top of heap
- Throws:
NoSuchElementException- ifisEmpty() == true
-
dequeue
public void dequeue(Activation activation)
-
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 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
protected void percolateUpMaxHeap(Activation element)
Percolates a new element up heap from the bottom.Assume it is a maximum heap.
- Parameters:
element- the element
-
-