private void ensureBufferCapacity(int numDocs) { if (buffers.isEmpty()) { addBuffer(additionalCapacity(numDocs)); return; } Buffer current = buffers.get(buffers.size() - 1); if (current.array.length - current.length >= numDocs) { // current buffer is large enough return; } if (current.length < current.array.length - (current.array.length >>> 3)) { // current buffer is less than 7/8 full, resize rather than waste space growBuffer(current, additionalCapacity(numDocs)); } else { addBuffer(additionalCapacity(numDocs)); } }
/** * Reserve space so that this builder can hold {@code numDocs} MORE documents. */ public void grow(int numDocs) { if (bitSet == null) { final long newLength = bufferSize + numDocs; if (newLength < threshold) { growBuffer((int) newLength); } else { upgradeToBitSet(); } } }
/** * Reserve space so that this builder can hold {@code numDocs} MORE documents. */ public void grow(int numDocs) { if (bitSet == null) { final long newLength = bufferSize + numDocs; if (newLength < threshold) { growBuffer((int) newLength); } else { upgradeToBitSet(); } } }
private void ensureBufferCapacity(int numDocs) { if (buffers.isEmpty()) { addBuffer(additionalCapacity(numDocs)); return; } Buffer current = buffers.get(buffers.size() - 1); if (current.array.length - current.length >= numDocs) { // current buffer is large enough return; } if (current.length < current.array.length - (current.array.length >>> 3)) { // current buffer is less than 7/8 full, resize rather than waste space growBuffer(current, additionalCapacity(numDocs)); } else { addBuffer(additionalCapacity(numDocs)); } }
/** * Add a document to this builder. * NOTE: doc IDs do not need to be provided in order. * NOTE: if you plan on adding several docs at once, look into using * {@link #grow(int)} to reserve space. */ public void add(int doc) { if (bitSet != null) { bitSet.set(doc); } else { if (bufferSize + 1 > buffer.length) { if (bufferSize + 1 >= threshold) { upgradeToBitSet(); bitSet.set(doc); return; } growBuffer(bufferSize+1); } buffer[bufferSize++] = doc; } }
/** * Add a document to this builder. * NOTE: doc IDs do not need to be provided in order. * NOTE: if you plan on adding several docs at once, look into using * {@link #grow(int)} to reserve space. */ public void add(int doc) { if (bitSet != null) { bitSet.set(doc); } else { if (bufferSize + 1 > buffer.length) { if (bufferSize + 1 >= threshold) { upgradeToBitSet(); bitSet.set(doc); return; } growBuffer(bufferSize+1); } buffer[bufferSize++] = doc; } }
growBuffer(bufferSize+1);
growBuffer(bufferSize+1);