class BoundedPriorityQueue {

    public Result offer( E element )
    {
        int updatedCount = count.incrementAndGet();
        if ( updatedCount > config.maxCount )
        {
            count.decrementAndGet();
            return E_COUNT_EXCEEDED;
        }

        long elementBytes = sizeOf.apply( element );
        long updatedBytes = bytes.addAndGet( elementBytes );

        if ( elementBytes != 0 && updatedCount > config.minCount )
        {
            if ( updatedBytes > config.maxBytes )
            {
                bytes.addAndGet( -elementBytes );
                count.decrementAndGet();
                return E_SIZE_EXCEEDED;
            }
        }

        if ( !queue.offer( new StableElement( element ) ) )
        {
            // this should not happen because we already have a reservation
            throw new IllegalStateException();
        }

        return OK;
    }

      BoundedPriorityQueue( Config config, Function<E,Long> sizeOf, java.util.Comparator<E> comparator );

}