presto-main/src/main/java/io/prestosql/operator/aggregation/TypedHeap.java/TypedHeap/add
class TypedHeap:    public void add(Block block, int position)
    {
        checkArgument(!block.isNull(position));
        if (positionCount == capacity) {
            if (comparator.compareTo(heapBlockBuilder, heapIndex[0], block, position) >= 0) {
                return; // and new element is not larger than heap top: do not add
            }
            heapIndex[0] = heapBlockBuilder.getPositionCount();
            type.appendTo(block, position, heapBlockBuilder);
            siftDown();
        }
        else {
            heapIndex[positionCount] = heapBlockBuilder.getPositionCount();
            positionCount++;
            type.appendTo(block, position, heapBlockBuilder);
            siftUp();
        }
        compactIfNecessary();
    }