Drools :: Core 6.0.0.Beta5

org.drools.core.util
Class BinaryHeapQueue

java.lang.Object
  extended by 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
protected static org.slf4j.Logger log
           
 
Constructor Summary
BinaryHeapQueue()
           
BinaryHeapQueue(Comparator comparator)
          Constructs a new BinaryHeap that will use the given comparator to order its elements.
BinaryHeapQueue(Comparator comparator, int capacity)
          Constructs a new BinaryHeap.
 
Method Summary
 void clear()
          Clears all elements from queue.
 Activation dequeue()
          Returns the Queueable on top of heap and remove it.
 Activation dequeue(int index)
           
 void enqueue(Activation element)
          Inserts an Queueable into queue.
 Activation[] getAndClear()
           
 boolean isEmpty()
          Tests if queue is empty.
 boolean isFull()
          Tests if queue is full.
 Activation peek()
           
protected  void percolateDownMaxHeap(int index)
          Percolates element down heap from the position given by the index.
protected  void percolateUpMaxHeap(Activation element)
          Percolates a new element up heap from the bottom.
protected  void percolateUpMaxHeap(int index)
          Percolates element up heap from from the position given by the index.
 void readExternal(ObjectInput in)
           
 int size()
          Returns the number of elements in this heap.
 Object[] toArray(Object[] a)
           
 void writeExternal(ObjectOutput out)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static transient org.slf4j.Logger log
Constructor Detail

BinaryHeapQueue

public BinaryHeapQueue()

BinaryHeapQueue

public BinaryHeapQueue(Comparator comparator)
Constructs a new BinaryHeap that 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 comparator,
                       int capacity)
Constructs a new BinaryHeap.

Parameters:
comparator - the comparator used to order the elements, null means use natural order
capacity - the initial capacity for the heap
Throws:
IllegalArgumentException - if capacity is <= 0
Method Detail

readExternal

public void readExternal(ObjectInput in)
                  throws IOException,
                         ClassNotFoundException
Specified by:
readExternal in interface Externalizable
Throws:
IOException
ClassNotFoundException

writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
Specified by:
writeExternal in interface Externalizable
Throws:
IOException

clear

public void clear()
Clears all elements from queue.


getAndClear

public Activation[] getAndClear()

isEmpty

public boolean isEmpty()
Tests if queue is empty.

Specified by:
isEmpty in interface Queue
Returns:
true if queue is empty; false otherwise.

isFull

public boolean isFull()
Tests if queue is full.

Returns:
true if queue is full; false otherwise.

size

public int size()
Returns the number of elements in this heap.

Returns:
the number of elements in this heap

peek

public Activation peek()

enqueue

public void enqueue(Activation element)
Inserts an Queueable into queue.

Specified by:
enqueue in interface Queue
Parameters:
element - the Queueable to be inserted

dequeue

public Activation dequeue()
                   throws NoSuchElementException
Returns the Queueable on top of heap and remove it.

Specified by:
dequeue in interface Queue
Returns:
the Queueable at top of heap
Throws:
NoSuchElementException - if isEmpty() == true

dequeue

public Activation dequeue(int index)
Specified by:
dequeue in interface Queue
Parameters:
index -

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

toArray

public Object[] toArray(Object[] a)

Drools :: Core 6.0.0.Beta5

Copyright © 2001-2013 JBoss by Red Hat. All Rights Reserved.