/** * Ensures that an array can contain the given number of entries, preserving * just a part of the array. * * @param array * an array. * @param length * the new minimum length for this array. * @param preserve * the number of elements of the array that must be preserved in case * a new allocation is necessary. * @return {@code array}, if it can contain {@code length} entries or more; * otherwise, an array with {@code length} entries whose first * {@code preserve} entries are the same as those of {@code array}. */ public static boolean[] ensureCapacity(final boolean[] array, final int length, final int preserve) { return length > array.length ? forceCapacity(array, length, preserve) : array; } /**
@Override public void size(final int size) { if (size > a.length) a = BooleanArrays.forceCapacity(a, size, this.size); if (size > this.size) Arrays.fill(a, this.size, size, (false)); this.size = size; } @Override
/** * Grows this array list, ensuring that it can contain the given number of * entries without resizing, and in case increasing the current capacity at * least by a factor of 50%. * * @param capacity * the new minimum capacity for this array list. */ private void grow(int capacity) { if (capacity <= a.length) return; if (a != BooleanArrays.DEFAULT_EMPTY_ARRAY) capacity = (int) Math.max( Math.min((long) a.length + (a.length >> 1), it.unimi.dsi.fastutil.Arrays.MAX_ARRAY_SIZE), capacity); else if (capacity < DEFAULT_INITIAL_CAPACITY) capacity = DEFAULT_INITIAL_CAPACITY; a = BooleanArrays.forceCapacity(a, capacity, size); assert size <= a.length; } @Override