in java/src/main/java/com/epam/deltix/containers/Heap.java [166:195]
public TValue pop() throws IndexOutOfBoundsException {
if (count == 0) throw new IndexOutOfBoundsException("Heap is empty");
if (isHeap) {
TValue returnValue = (TValue) elements[0];
TValue value = (TValue) elements[count - 1];
count--;
int current = 0;
while (current < count) {
int left = (current << 1) + 1;
int right = (current << 1) + 2;
int swapIndex = current;
if (left >= count) swapIndex = current;
else if (right >= count) {
if (comparator.compare((TValue) elements[left], value) < 0) swapIndex = left;
} else {
if (comparator.compare((TValue) elements[left], (TValue) elements[right]) < 0) {
if (comparator.compare((TValue) elements[left], value) < 0) swapIndex = left;
} else if (comparator.compare((TValue) elements[right], value) < 0) swapIndex = right;
}
if (swapIndex == current) break;
elements[current] = elements[swapIndex];
current = swapIndex;
}
elements[current] = value;
return returnValue;
} else {
count--;
return (TValue) elements[count];
}
}