public void modifyTop()

in java/src/main/java/com/epam/deltix/containers/HeapWithAttachments.java [253:280]


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