/** * Ensures that this big-array big list can contain the given number of entries * without resizing. * * @param capacity * the new minimum capacity for this big-array big list. */ public void ensureCapacity(final long capacity) { if (capacity <= a.length || a == IntBigArrays.DEFAULT_EMPTY_BIG_ARRAY) return; a = IntBigArrays.forceCapacity(a, capacity, size); assert size <= IntBigArrays.length(a); } /**
/** * Ensures that a big array can contain the given number of entries, preserving * just a part of the big array. * * <p> * <strong>Warning:</strong> the returned array might use part of the segments * of the original array, which must be considered read-only after calling this * method. * * @param array * a big array. * @param length * the new minimum length for this big array. * @param preserve * the number of elements of the big 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, a big array with {@code length} entries whose first * {@code preserve} entries are the same as those of {@code array}. */ public static int[][] ensureCapacity(final int[][] array, final long length, final long preserve) { return length > length(array) ? forceCapacity(array, length, preserve) : array; } /**
@Override public void size(final long size) { if (size > IntBigArrays.length(a)) a = IntBigArrays.forceCapacity(a, size, this.size); if (size > this.size) IntBigArrays.fill(a, this.size, size, (0)); this.size = size; } @Override
/** * Grows this big-array big list, ensuring that it can contain the given number * of entries without resizing, and in case increasing current capacity at least * by a factor of 50%. * * @param capacity * the new minimum capacity for this big-array big list. */ private void grow(long capacity) { final long oldLength = IntBigArrays.length(a); if (capacity <= oldLength) return; if (a != IntBigArrays.DEFAULT_EMPTY_BIG_ARRAY) capacity = Math.max(oldLength + (oldLength >> 1), capacity); else if (capacity < DEFAULT_INITIAL_CAPACITY) capacity = DEFAULT_INITIAL_CAPACITY; a = IntBigArrays.forceCapacity(a, capacity, size); assert size <= IntBigArrays.length(a); } @Override