code: public void removeAtBufferIndex(int index) {
      assert (head <= tail 
        ? index >= head && index < tail
        : index >= head || index < tail) : "Index out of range (head=" 
            + head + ", tail=" + tail + ", index=" + index + ").";
  
      // Cache fields in locals (hopefully moved to registers).
      final KType [] buffer = Intrinsics.<KType[]> cast(this.buffer);
      final int bufLen = buffer.length;
      final int lastIndex = bufLen - 1;
      final int head = this.head;
      final int tail = this.tail;
  
      final int leftChunk = Math.abs(index - head) % bufLen;
      final int rightChunk = Math.abs(tail - index) % bufLen;
  
      if (leftChunk < rightChunk) {
        if (index >= head) {
          System.arraycopy(buffer, head, buffer, head + 1, leftChunk);
        } else {
          System.arraycopy(buffer, 0, buffer, 1, index);
          buffer[0] = buffer[lastIndex];
          System.arraycopy(buffer, head, buffer, head + 1, lastIndex - head);
        }
        buffer[head] = Intrinsics.empty();
        this.head = oneRight(head, bufLen);
      } else {
        if (index < tail) {
          System.arraycopy(buffer, index + 1, buffer, index, rightChunk);
        } else {
          System.arraycopy(buffer, index + 1, buffer, index, lastIndex - index);
          buffer[lastIndex] = buffer[0];
          System.arraycopy(buffer, 1, buffer, 0, tail);
        }
        buffer[tail] = Intrinsics.empty();
        this.tail = oneLeft(tail, bufLen);
      }
    }
docs: Removes the element at <code>index</code> in the internal {#link
  {@link #buffer} array, returning its value.
  
  @param index
  Index of the element to remove. The index must be located between
  {@link #head} and {@link #tail} in modulo {@link #buffer}
  arithmetic.