/** Create a {@link GrowableByteArrayDataOutput} with the given initial capacity. */ public GrowableByteArrayDataOutput(int cp) { this.bytes = new byte[ArrayUtil.oversize(cp, 1)]; this.length = 0; }
private void growTermBuffer(int newSize) { if(termBuffer.length < newSize){ // Not big enough; create a new array with slight // over allocation: termBuffer = new char[ArrayUtil.oversize(newSize, Character.BYTES)]; } }
void addFieldToFlush(TermVectorsConsumerPerField fieldToFlush) { if (numVectorFields == perFields.length) { int newSize = ArrayUtil.oversize(numVectorFields + 1, RamUsageEstimator.NUM_BYTES_OBJECT_REF); TermVectorsConsumerPerField[] newArray = new TermVectorsConsumerPerField[newSize]; System.arraycopy(perFields, 0, newArray, 0, numVectorFields); perFields = newArray; } perFields[numVectorFields++] = fieldToFlush; }
@Override public final char[] resizeBuffer(int newSize) { if(termBuffer.length < newSize){ // Not big enough; create a new array with slight // over allocation and preserve content final char[] newCharBuffer = new char[ArrayUtil.oversize(newSize, Character.BYTES)]; System.arraycopy(termBuffer, 0, newCharBuffer, 0, termBuffer.length); termBuffer = newCharBuffer; } return termBuffer; }
/** Returns an array whose size is at least {@code minSize}, generally over-allocating exponentially */ public static float[] grow(float[] array, int minSize) { assert minSize >= 0: "size must be positive (got " + minSize + "): likely integer overflow?"; if (array.length < minSize) { float[] copy = new float[oversize(minSize, Float.BYTES)]; System.arraycopy(array, 0, copy, 0, array.length); return copy; } else return array; }
@Override public int[] init() { final int[] ord = super.init(); boost = new float[ArrayUtil.oversize(ord.length, Float.BYTES)]; termState = new TermContext[ArrayUtil.oversize(ord.length, RamUsageEstimator.NUM_BYTES_OBJECT_REF)]; assert termState.length >= ord.length && boost.length >= ord.length; return ord; }
/** Returns an array whose size is at least {@code minSize}, generally over-allocating exponentially */ public static double[] grow(double[] array, int minSize) { assert minSize >= 0: "size must be positive (got " + minSize + "): likely integer overflow?"; if (array.length < minSize) { return growExact(array, oversize(minSize, Double.BYTES)); } else return array; }
/** Returns an array whose size is at least {@code minSize}, generally over-allocating exponentially */ public static int[] grow(int[] array, int minSize) { assert minSize >= 0: "size must be positive (got " + minSize + "): likely integer overflow?"; if (array.length < minSize) { return growExact(array, oversize(minSize, Integer.BYTES)); } else return array; }
/** Returns an array whose size is at least {@code minSize}, generally over-allocating exponentially */ public static short[] grow(short[] array, int minSize) { assert minSize >= 0: "size must be positive (got " + minSize + "): likely integer overflow?"; if (array.length < minSize) { return growExact(array, oversize(minSize, Short.BYTES)); } else return array; }
/** Returns an array whose size is at least {@code minSize}, generally over-allocating exponentially */ public static long[] grow(long[] array, int minSize) { assert minSize >= 0: "size must be positive (got " + minSize + "): likely integer overflow?"; if (array.length < minSize) { return growExact(array, oversize(minSize, Long.BYTES)); } else return array; }
/** Returns an array whose size is at least {@code minSize}, generally over-allocating exponentially */ public static char[] grow(char[] array, int minSize) { assert minSize >= 0: "size must be positive (got " + minSize + "): likely integer overflow?"; if (array.length < minSize) { return growExact(array, oversize(minSize, Character.BYTES)); } else return array; }
private FST.Arc<BytesRef> getArc(int ord) { if (ord >= arcs.length) { @SuppressWarnings({"rawtypes","unchecked"}) final FST.Arc<BytesRef>[] next = new FST.Arc[ArrayUtil.oversize(1+ord, RamUsageEstimator.NUM_BYTES_OBJECT_REF)]; System.arraycopy(arcs, 0, next, 0, arcs.length); for(int arcOrd=arcs.length;arcOrd<next.length;arcOrd++) { next[arcOrd] = new FST.Arc<>(); } arcs = next; } return arcs[ord]; }
/** Returns an array whose size is at least {@code minSize}, generally over-allocating exponentially */ public static byte[] grow(byte[] array, int minSize) { assert minSize >= 0: "size must be positive (got " + minSize + "): likely integer overflow?"; if (array.length < minSize) { return growExact(array, oversize(minSize, Byte.BYTES)); } else return array; }
private SegmentTermsEnumFrame getFrame(int ord) throws IOException { if (ord >= stack.length) { final SegmentTermsEnumFrame[] next = new SegmentTermsEnumFrame[ArrayUtil.oversize(1+ord, RamUsageEstimator.NUM_BYTES_OBJECT_REF)]; System.arraycopy(stack, 0, next, 0, stack.length); for(int stackOrd=stack.length;stackOrd<next.length;stackOrd++) { next[stackOrd] = new SegmentTermsEnumFrame(this, stackOrd); } stack = next; } assert stack[ord].ord == ord; return stack[ord]; }
private FST.Arc<BytesRef> getArc(int ord) { if (ord >= arcs.length) { @SuppressWarnings({"rawtypes","unchecked"}) final FST.Arc<BytesRef>[] next = new FST.Arc[ArrayUtil.oversize(1+ord, RamUsageEstimator.NUM_BYTES_OBJECT_REF)]; System.arraycopy(arcs, 0, next, 0, arcs.length); for(int arcOrd=arcs.length;arcOrd<next.length;arcOrd++) { next[arcOrd] = new FST.Arc<>(); } arcs = next; } return arcs[ord]; }
/** Returns an array whose size is at least {@code minSize}, generally over-allocating exponentially */ public static <T> T[] grow(T[] array, int minSize) { assert minSize >= 0 : "size must be positive (got " + minSize + "): likely integer overflow?"; if (array.length < minSize) { final int newLength = oversize(minSize, RamUsageEstimator.NUM_BYTES_OBJECT_REF); return growExact(array, newLength); } else return array; }
private IntersectTermsEnumFrame getFrame(int ord) throws IOException { if (ord >= stack.length) { final IntersectTermsEnumFrame[] next = new IntersectTermsEnumFrame[ArrayUtil.oversize(1+ord, RamUsageEstimator.NUM_BYTES_OBJECT_REF)]; System.arraycopy(stack, 0, next, 0, stack.length); for(int stackOrd=stack.length;stackOrd<next.length;stackOrd++) { next[stackOrd] = new IntersectTermsEnumFrame(this, stackOrd); } stack = next; } assert stack[ord].ord == ord; return stack[ord]; }
@Override public final void collect( int doc ) throws IOException { docs.addDoc( doc ); if ( keepScores ) { if ( segmentHits >= scores.length ) { float[] newScores = new float[ArrayUtil.oversize( segmentHits + 1, 4 )]; System.arraycopy( scores, 0, newScores, 0, segmentHits ); scores = newScores; } scores[segmentHits] = scorer.score(); } segmentHits++; totalHits++; }
@Override public int[] grow() { final int[] ord = super.grow(); boost = ArrayUtil.grow(boost, ord.length); if (termState.length < ord.length) { TermContext[] tmpTermState = new TermContext[ArrayUtil.oversize(ord.length, RamUsageEstimator.NUM_BYTES_OBJECT_REF)]; System.arraycopy(termState, 0, tmpTermState, 0, termState.length); termState = tmpTermState; } assert termState.length >= ord.length && boost.length >= ord.length; return ord; }
final ParallelPostingsArray grow() { int newSize = ArrayUtil.oversize(size + 1, bytesPerPosting()); ParallelPostingsArray newArray = newInstance(newSize); copyTo(newArray, size); return newArray; }