use of org.drools.core.spi.Activation in project drools by kiegroup.
the class BinaryHeapQueue method dequeue.
Activation dequeue(final int index) {
if (index < 1 || index > this.size) {
// throw new NoSuchElementException();
return null;
}
final Activation result = this.elements[index];
if (log.isTraceEnabled()) {
log.trace("Queue Removed {} {}", result.getQueueIndex(), result);
}
setElement(index, this.elements[this.size]);
this.elements[this.size] = null;
this.size--;
if (this.size != 0 && index <= this.size) {
int compareToParent = 0;
if (index > 1) {
compareToParent = compare(this.elements[index], this.elements[index / 2]);
}
if (index > 1 && compareToParent > 0) {
percolateUpMaxHeap(index);
} else {
percolateDownMaxHeap(index);
}
}
result.setQueued(false);
result.setQueueIndex(-1);
return result;
}
use of org.drools.core.spi.Activation in project drools by kiegroup.
the class BinaryHeapQueue method percolateUpMaxHeap.
/**
* Percolates element up heap from from the position given by the index.
* <p>
* Assume it is a maximum heap.
*
* @param index the index of the element to be percolated up
*/
protected void percolateUpMaxHeap(final int index) {
int hole = index;
Activation element = elements[hole];
while (hole > 1 && compare(element, elements[hole / 2]) > 0) {
// save element that is being pushed down
// as the element "bubble" is percolated up
final int next = hole / 2;
setElement(hole, elements[next]);
hole = next;
}
setElement(hole, element);
}
Aggregations