Expand the underlying byte buffer to contain the specified delta
@param delta amount needed to accommodate the next buffer append
543218
protected void ensureCapacity(int delta) {
        if (m_bb.position() + delta > m_bb.capacity()) {
            ByteBuffer oldbb = m_bb.asReadOnlyBuffer();
            oldbb.flip();

            int newCapacity = oldbb.capacity() * 2;
            while (newCapacity < (oldbb.capacity() + delta)) {
                newCapacity *= 2;
            }

            ByteBuffer newbb = ByteBuffer.allocateDirect(newCapacity);
            newbb.put(oldbb);

            DBBPool.wrapBB(m_bb).discard();
            m_bb = newbb;
        }
    }
391650
protected void ensureAvailableBytes(int amount) throws IOException {
		if (!this.seekEnabled && amount > this.buffer.remaining()) {
			this.bufferPosition += this.buffer.position();
			this.buffer.compact();
			int limit = this.buffer.position();
			final int read = this.stream.read(this.buffer);
			if (read < 0) {
				if (limit == 0) {
					throw new EOFException();
				}
			} else {
				limit += read;
			}
			this.buffer.rewind();
			this.buffer.limit(limit);

		}
		if (amount > this.buffer.remaining()) {
			throw new EOFException();
		}
	}
1014255
@Override
  public void put(double val) {
    if(this.n == 0) {
      n = 1.;
      min = max = sum = val;
      m2 = m3 = m4 = 0;
      return;
    }
    final double nn = this.n + 1.0;
    final double deltan = val * n - sum;
    final double delta_nn = deltan / (n * nn);
    final double delta_nn2 = delta_nn * delta_nn;
    final double inc = deltan * delta_nn;

    // Update values:
    m4 += inc * delta_nn2 * (nn * (nn - 3.) + 3.) + 6. * delta_nn2 * m2 - 4. * delta_nn * m3;
    m3 += inc * delta_nn * (nn - 2) - 3. * delta_nn * m2;
    m2 += inc;
    sum += val;
    n = nn;

    min = Math.min(min, val);
    max = Math.max(max, val);
  }
353757
@SuppressWarnings("unchecked")
    public synchronized void expand(int additionalCapacity) {
        if (additionalCapacity <= 0) {
            throw new IllegalArgumentException();
        }

        int capacityBefore = buffer.length;
        synchronized (lock) { // D312598
            int capacityAfter = buffer.length;
            //Check that no one was expanding while we waited on this lock
            if (capacityAfter == capacityBefore) {
                final Object[] newBuffer = new Object[buffer.length + additionalCapacity];

                // PK53203 - put() acquires two locks in sequence.  First, it acquires
                // the insert lock to update putIndex.  Then, it drops the insert lock
                // and acquires the extract lock to update numberOfUsedSlots.  As a
                // result, there is a window where putIndex has been updated, but
                // numberOfUsedSlots has not.  Consequently, even though we have
                // acquired both locks in this method, we cannot rely on the values in
                // numberOfUsedSlots; we can only rely on putIndex and takeIndex.

                if (putIndex > takeIndex) {
                    // The contents of the buffer do not wrap round
                    // the end of the array. We can move its contents
                    // into the new expanded buffer in one go.

                    int used = putIndex - takeIndex;
                    System.arraycopy(buffer, takeIndex, newBuffer, 0, used);
                    putIndex = used;

                    // PK53203.1 - If putIndex == takeIndex, then the buffer is either
                    // completely full or completely empty.  If it is completely full, then
                    // we need to copy and adjust putIndex.  Otherwise, we need to set
                    // putIndex to 0.
                } else if (putIndex != takeIndex || buffer[takeIndex] != null) {
                    // The contents of the buffer wrap round the end
                    // of the array. We have to perform two copies to
                    // move its contents into the new buffer.

                    int used = buffer.length - takeIndex;
                    System.arraycopy(buffer, takeIndex, newBuffer, 0, used);
                    System.arraycopy(buffer, 0, newBuffer, used, putIndex);
                    putIndex += used;
                } else {
                    putIndex = 0;
                }

                // The contents of the buffer now begin at 0 - update the head pointer.

                takeIndex = 0;

                // The buffer's capacity has been increased so update the count of the
                // empty slots to reflect this.
                buffer = (T[]) newBuffer;
            }
        } // D312598
    }
1028780
public void addByte(int b)
    throws IOException
  {
    int nextHead = (_byteHead + 1) % _byteBuffer.length;

    while (nextHead == _byteTail) {
      int ch = readChar();

      if (ch < 0) {
        break;
      }

      outputChar(ch);
    }

    _byteBuffer[_byteHead] = (byte) b;
    _byteHead = nextHead;
  }
210736
public WrappedByteBuffer putBuffer(WrappedByteBuffer v) {
        _autoExpand(v.remaining());
        _buf.put(v._buf);
        return this;
    }
517239
@Deprecated
  public void addDeltaField(String... deltaFieldName) {
    StringBuilder sb = new StringBuilder(getProp(ConfigurationKeys.EXTRACT_DELTA_FIELDS_KEY, ""));
    Joiner.on(",").appendTo(sb, deltaFieldName);
    setProp(ConfigurationKeys.EXTRACT_DELTA_FIELDS_KEY, sb.toString());
  }
680477
public void add(byte b) throws BufferIsFullException {
        if (isFull()) {
            throw new BufferIsFullException("Buffer is full and has reached maximum capacity (" + capacity() + ")");
        }

        // buffer is not full
        this.buffer[this.currentWritePosition] = b;
        this.currentWritePosition = (this.currentWritePosition + 1) % this.buffer.length;
        this.currentBufferSize += 1;
    }
647889
public final void addToPendingCount(int delta) {
        int c; // note: can replace with intrinsic in jdk8
        do {} while (!U.compareAndSwapInt(this, PENDING, c = pending, c+delta));
    }
243552
private void readDeltaValues(int firstByte)
            throws IOException
    {
        // extract the number of fixed bits
        int fixedBits = (firstByte >>> 1) & 0x1f;
        if (fixedBits != 0) {
            fixedBits = LongDecode.decodeBitWidth(fixedBits);
        }

        // extract the blob run length
        int length = (firstByte & 0x01) << 8;
        length |= input.read();

        // read the first value stored as vint
        long firstVal = LongDecode.readVInt(signed, input);

        // store first value to result buffer
        literals[numLiterals++] = firstVal;

        // if fixed bits is 0 then all values have fixed delta
        long prevVal;
        if (fixedBits == 0) {
            // read the fixed delta value stored as vint (deltas can be negative even
            // if all number are positive)
            long fixedDelta = LongDecode.readSignedVInt(input);

            // add fixed deltas to adjacent values
            for (int i = 0; i < length; i++) {
                literals[numLiterals++] = literals[numLiterals - 2] + fixedDelta;
            }
        }
        else {
            long deltaBase = LongDecode.readSignedVInt(input);
            // add delta base and first value
            literals[numLiterals++] = firstVal + deltaBase;
            prevVal = literals[numLiterals - 1];
            length -= 1;

            // write the unpacked values, add it to previous value and store final
            // value to result buffer. if the delta base value is negative then it
            // is a decreasing sequence else an increasing sequence
            packer.unpack(literals, numLiterals, length, fixedBits, input);
            while (length > 0) {
                if (deltaBase < 0) {
                    literals[numLiterals] = prevVal - literals[numLiterals];
                }
                else {
                    literals[numLiterals] = prevVal + literals[numLiterals];
                }
                prevVal = literals[numLiterals];
                length--;
                numLiterals++;
            }
        }
    }
694794
protected final void expand (int needed)
    {
        int ocapacity = _buffer.capacity();
        int ncapacity = _buffer.position() + needed;
        if (ncapacity > ocapacity) {
            // increase the buffer size in large increments
            ncapacity = Math.max(ocapacity << 1, ncapacity);
            ByteBuffer newbuf = ByteBuffer.allocate(ncapacity);
            newbuf.put((ByteBuffer)_buffer.flip());
            _buffer = newbuf;
        }
    }
1280292
public int addAndGetLo(int delta) {
        while (true) {
            long encoded = get();
            int lo = getLo(encoded) + delta;
            long update = encodeLo(encoded, lo);
            if (compareAndSet(encoded, update))
                return lo;
        }
    }
636431
private void expandBuffers() {
    if (this.serialized.length < size + ARC_SIZE * MAX_LABELS) {
      serialized = java.util.Arrays.copyOf(serialized, serialized.length + bufferGrowthSize);
      serializationBufferReallocations++;
    }
  }
397975
public void add(T item, long delta) {
        MutableLong entry = map.get(item);
        if (entry == null) {
            entry = MutableLong.valueOf(delta);
            map.put(item, entry);
        } else {
            entry.value += delta;
        }
        total += delta;
    }
975302
private void expand(int i) {
        /* Can the buffer handle @i more bytes, if not expand it */
        if (count + i <= buf.length) {
            return;
        }
        byte[] newbuf = mPool.getBuf((count + i) * 2);
        System.arraycopy(buf, 0, newbuf, 0, count);
        mPool.returnBuf(buf);
        buf = newbuf;
    }
444277
@Override
	// @NotThreadSafe
	protected void ensureCapacity(long capacity) throws IOException {
		long curCapacity = pbuffer.capacity();
		if(curCapacity<capacity) expandCapacity(curCapacity, capacity);
	}
1356822
function __expand(bytes) {

        // Resize buffer if more space needed
        if (length+bytes >= buffer.length) {
            var new_buffer = new Uint8Array((length+bytes)*2);
            new_buffer.set(buffer);
            buffer = new_buffer;
        }

        length += bytes;

    }