in drools-benchmarks-parent/drools-benchmarks/src/main/java/org/drools/benchmarks/datastructures/BinaryHeapQueue.java [172:195]
protected void percolateDownMaxHeap(final int index) {
final T element = elements.get(index);
int hole = index;
while ((hole * 2) <= size) {
int child = hole * 2;
// if we have a right child and that child can not be percolated
// up then move onto other child
if (child != size && compare(elements.get(child + 1), elements.get(child)) > 0) {
child++;
}
// if we found resting place of bubble then terminate search
if (compare(elements.get(child), element) <= 0) {
break;
}
setElement( hole, elements.get(child) );
hole = child;
}
setElement( hole, element);
}