public static int getShrinkSize(int currentSize, int targetSize) { final int newSize = getNextSize(targetSize); // Only reallocate if we are "substantially" smaller. // This saves us from "running hot" (constantly making a // bit bigger then a bit smaller, over and over): if (newSize < currentSize/2) return newSize; else return currentSize; }
public static int getShrinkSize(int currentSize, int targetSize) { final int newSize = getNextSize(targetSize); // Only reallocate if we are "substantially" smaller. // This saves us from "running hot" (constantly making a // bit bigger then a bit smaller, over and over): if (newSize < currentSize/2) return newSize; else return currentSize; }
public static int[] grow(int[] array, int minSize) { if (array.length < minSize) { int[] newArray = new int[getNextSize(minSize)]; System.arraycopy(array, 0, newArray, 0, array.length); return newArray; } else return array; }
public static byte[] grow(byte[] array, int minSize) { if (array.length < minSize) { byte[] newArray = new byte[getNextSize(minSize)]; System.arraycopy(array, 0, newArray, 0, array.length); return newArray; } else return array; }
public static long[] grow(long[] array, int minSize) { if (array.length < minSize) { long[] newArray = new long[getNextSize(minSize)]; System.arraycopy(array, 0, newArray, 0, array.length); return newArray; } else return array; }
public static long[] grow(long[] array, int minSize) { if (array.length < minSize) { long[] newArray = new long[getNextSize(minSize)]; System.arraycopy(array, 0, newArray, 0, array.length); return newArray; } else return array; }
public static byte[] grow(byte[] array, int minSize) { if (array.length < minSize) { byte[] newArray = new byte[getNextSize(minSize)]; System.arraycopy(array, 0, newArray, 0, array.length); return newArray; } else return array; }
public static int[] grow(int[] array, int minSize) { if (array.length < minSize) { int[] newArray = new int[getNextSize(minSize)]; System.arraycopy(array, 0, newArray, 0, array.length); return newArray; } else return array; }
/** Allocates a buffer char[] of at least newSize * @param newSize minimum size of the buffer * @return newly created buffer with length >= newSize or null if the current termBuffer is big enough */ private char[] growTermBuffer(int newSize) { if (termBuffer != null) { if (termBuffer.length >= newSize) // Already big enough return null; else // Not big enough; create a new array with slight // over allocation: return new char[ArrayUtil.getNextSize(newSize)]; } else { // determine the best size // The buffer is always at least MIN_BUFFER_SIZE if (newSize < MIN_BUFFER_SIZE) { newSize = MIN_BUFFER_SIZE; } // If there is already a termText, then the size has to be at least that big if (termText != null) { int ttLength = termText.length(); if (newSize < ttLength) { newSize = ttLength; } } return new char[newSize]; } }
/** Allocates a buffer char[] of at least newSize * @param newSize minimum size of the buffer * @return newly created buffer with length >= newSize or null if the current termBuffer is big enough */ private char[] growTermBuffer(int newSize) { if (termBuffer != null) { if (termBuffer.length >= newSize) // Already big enough return null; else // Not big enough; create a new array with slight // over allocation: return new char[ArrayUtil.getNextSize(newSize)]; } else { // determine the best size // The buffer is always at least MIN_BUFFER_SIZE if (newSize < MIN_BUFFER_SIZE) { newSize = MIN_BUFFER_SIZE; } // If there is already a termText, then the size has to be at least that big if (termText != null) { int ttLength = termText.length(); if (newSize < ttLength) { newSize = ttLength; } } return new char[newSize]; } }
synchronized PerDoc getPerDoc() { if (freeCount == 0) { allocCount++; if (allocCount > docFreeList.length) { // Grow our free list up front to make sure we have // enough space to recycle all outstanding PerDoc // instances assert allocCount == 1+docFreeList.length; docFreeList = new PerDoc[ArrayUtil.getNextSize(allocCount)]; } return new PerDoc(); } else return docFreeList[--freeCount]; }
synchronized PerDoc getPerDoc() { if (freeCount == 0) { allocCount++; if (allocCount > docFreeList.length) { // Grow our free list up front to make sure we have // enough space to recycle all outstanding PerDoc // instances assert allocCount == 1+docFreeList.length; docFreeList = new PerDoc[ArrayUtil.getNextSize(allocCount)]; } return new PerDoc(); } else return docFreeList[--freeCount]; }
synchronized PerDoc getPerDoc() { if (freeCount == 0) { allocCount++; if (allocCount > docFreeList.length) { // Grow our free list up front to make sure we have // enough space to recycle all outstanding PerDoc // instances assert allocCount == 1+docFreeList.length; docFreeList = new PerDoc[ArrayUtil.getNextSize(allocCount)]; } return new PerDoc(); } else return docFreeList[--freeCount]; }
synchronized PerDoc getPerDoc() { if (freeCount == 0) { allocCount++; if (allocCount > docFreeList.length) { // Grow our free list up front to make sure we have // enough space to recycle all outstanding PerDoc // instances assert allocCount == 1+docFreeList.length; docFreeList = new PerDoc[ArrayUtil.getNextSize(allocCount)]; } return new PerDoc(); } else return docFreeList[--freeCount]; }
synchronized PerDoc getPerDoc() { if (freeCount == 0) { allocCount++; if (allocCount > docFreeList.length) { // Grow our free list up front to make sure we have // enough space to recycle all outstanding PerDoc // instances assert allocCount == 1+docFreeList.length; docFreeList = new PerDoc[ArrayUtil.getNextSize(allocCount)]; } return new PerDoc(); } else return docFreeList[--freeCount]; }
synchronized PerDoc getPerDoc() { if (freeCount == 0) { allocCount++; if (allocCount > docFreeList.length) { // Grow our free list up front to make sure we have // enough space to recycle all outstanding PerDoc // instances assert allocCount == 1+docFreeList.length; docFreeList = new PerDoc[ArrayUtil.getNextSize(allocCount)]; } return new PerDoc(); } else return docFreeList[--freeCount]; }
if (gap >= waiting.length) { DocWriter[] newArray = new DocWriter[ArrayUtil.getNextSize(gap)]; assert nextWriteLoc >= 0; System.arraycopy(waiting, nextWriteLoc, newArray, 0, waiting.length-nextWriteLoc);
if (gap >= waiting.length) { DocWriter[] newArray = new DocWriter[ArrayUtil.getNextSize(gap)]; assert nextWriteLoc >= 0; System.arraycopy(waiting, nextWriteLoc, newArray, 0, waiting.length-nextWriteLoc);
postingsFreeList = new RawPostingList[ArrayUtil.getNextSize(newPostingsAllocCount)];
postingsFreeList = new RawPostingList[ArrayUtil.getNextSize(newPostingsAllocCount)];