/** * Trims the underlying heap array so that it has exactly {@link #size()} * elements. */ public void trim() { heap = LongArrays.trim(heap, size); } @Override
/** * Trims the underlying array so that it has exactly {@link #size()} elements. */ public void trim() { array = LongArrays.trim(array, size); } @Override
/** * Sets the length of the given array. * * @param array * an array. * @param length * the new length for the array. * @return {@code array}, if it contains exactly {@code length} entries; * otherwise, if it contains <em>more</em> than {@code length} entries, * an array with {@code length} entries whose entries are the same as * the first {@code length} entries of {@code array}; otherwise, an * array with {@code length} entries whose first {@code array.length} * entries are the same as those of {@code array}. * */ public static long[] setLength(final long[] array, final int length) { if (length == array.length) return array; if (length < array.length) return trim(array, length); return ensureCapacity(array, length); } /**
/** * Trims the given big array to the given length. * * <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 maximum length for the big array. * @return {@code array}, if it contains {@code length} entries or less; * otherwise, a big array with {@code length} entries whose entries are * the same as the first {@code length} entries of {@code array}. * */ public static long[][] trim(final long[][] array, final long length) { ensureLength(length); final long oldLength = length(array); if (length >= oldLength) return array; final int baseLength = (int) ((length + SEGMENT_MASK) >>> SEGMENT_SHIFT); final long[][] base = Arrays.copyOf(array, baseLength); final int residual = (int) (length & SEGMENT_MASK); if (residual != 0) base[baseLength - 1] = LongArrays.trim(base[baseLength - 1], residual); return base; } /**
/** * Unwraps an iterator, returning an array, with a limit on the number of * elements. * * <p> * This method iterates over the given type-specific iterator and returns an * array containing the elements returned by the iterator. At most {@code max} * elements will be returned. * * @param i * a type-specific iterator. * @param max * the maximum number of elements to be unwrapped. * @return an array containing the elements returned by the iterator (at most * {@code max}). */ public static long[] unwrap(final LongIterator i, int max) { if (max < 0) throw new IllegalArgumentException("The maximum number of elements (" + max + ") is negative"); long array[] = new long[16]; int j = 0; while (max-- != 0 && i.hasNext()) { if (j == array.length) array = LongArrays.grow(array, j + 1); array[j++] = i.nextLong(); } return LongArrays.trim(array, j); } /**
this.ratio = ratio; this.array = ShortBigArrays.trim(array, curSize); this.p = LongArrays.trim(p, (n + ratio - 1) / ratio);
this.ratio = ratio; this.array = IntBigArrays.trim(array, curSize); this.p = LongArrays.trim(p, (n + ratio - 1) / ratio);
this.ratio = ratio; this.array = ByteBigArrays.trim(array, curSize); this.p = LongArrays.trim(p, (n + ratio - 1) / ratio);
this.ratio = ratio; this.array = CharBigArrays.trim(array, curSize); this.p = LongArrays.trim(p, (n + ratio - 1) / ratio);
this.ratio = ratio; this.array = LongBigArrays.trim(array, curSize); this.p = LongArrays.trim(p, (n + ratio - 1) / ratio);