public void pop()

in java/src/main/java/com/epam/deltix/containers/HeapWithAttachments.java [177:206]


    public void pop() throws IndexOutOfBoundsException {
        if (count == 0) throw new IndexOutOfBoundsException("Heap is empty");
        if (isHeap) {
            TValue tempValue = (TValue) elementsValue[count - 1];
            TAttachments tempAttachment = (TAttachments) elementsAttachment[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) elementsValue[left], tempValue) < 0) swapIndex = left;
                } else {
                    if (comparator.compare((TValue) elementsValue[left], (TValue) elementsValue[right]) < 0) {
                        if (comparator.compare((TValue) elementsValue[left], tempValue) < 0) swapIndex = left;
                    } else if (comparator.compare((TValue) elementsValue[right], tempValue) < 0) swapIndex = right;
                }
                if (swapIndex == current) break;
                elementsValue[current] = elementsValue[swapIndex];
                elementsAttachment[current] = elementsAttachment[swapIndex];
                current = swapIndex;
            }
            elementsValue[current] = tempValue;
            elementsAttachment[current] = tempAttachment;
        } else {
            count--;
        }
    }