/** * Grows the given array to the maximum between the given length and the current * length increased by 50%, provided that the given length is larger than the * current length. * * <p> * If you want complete control on the array growth, you should probably use * {@code ensureCapacity()} instead. * * @param array * an array. * @param length * the new minimum length for this array. * @return {@code array}, if it can contain {@code length} entries; otherwise, * an array with max({@code length},{@code array.length}/φ) entries * whose first {@code array.length} entries are the same as those of * {@code array}. */ public static long[] grow(final long[] array, final int length) { return grow(array, length, array.length); } /**
@Override public void enqueue(long x) { if (size == heap.length) heap = LongArrays.grow(heap, size + 1); heap[size++] = x; LongHeaps.upHeap(heap, size, size - 1, c); } @Override
@Override public void enqueue(long x) { if (size == array.length) array = LongArrays.grow(array, size + 1); if (firstIndexValid) { if (c == null) { if (((x) < (array[firstIndex]))) firstIndex = size; } else if (c.compare(x, array[firstIndex]) < 0) firstIndex = size; } else firstIndexValid = false; array[size++] = x; } @Override
/** Ensures that this bit vector can hold the specified number of bits. * * <p>This method uses {@link LongArrays#grow(long[], int, int)} to * ensure that there is enough space for the given number of bits. As a * consequence, the actual length of the long array allocated might be * larger than expected. * * @param numBits the number of bits that this vector must be able to contain. * @return this bit vector. */ public LongArrayBitVector ensureCapacity(final long numBits) { if (numBits > (long)Integer.MAX_VALUE * Long.SIZE) throw new IndexOutOfBoundsException("In this implementations bit vectors can be at most 2^37 - 64 bits long"); bits = LongArrays.grow(bits, numWords(numBits), numWords(length)); return this; }
/** Ensures that this bit vector can hold the specified number of bits. * * <p>This method uses {@link LongArrays#grow(long[], int, int)} to * ensure that there is enough space for the given number of bits. As a * consequence, the actual length of the long array allocated might be * larger than expected. * * @param numBits the number of bits that this vector must be able to contain. * @return this bit vector. */ public LongArrayBitVector ensureCapacity( final long numBits ) { bits = LongArrays.grow( bits, numWords( numBits ), numWords( length ) ); return this; }
/** Ensures that this bit vector can hold the specified number of bits. * * <p>This method uses {@link LongArrays#grow(long[], int, int)} to * ensure that there is enough space for the given number of bits. As a * consequence, the actual length of the long array allocated might be * larger than expected. * * @param numBits the number of bits that this vector must be able to contain. * @return this bit vector. */ public LongArrayBitVector ensureCapacity( final long numBits ) { bits = LongArrays.grow( bits, numWords( numBits ), numWords( length ) ); return this; }
/** * 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); } /**
@Override public void add(final long index, final boolean value) { if (CHECKS) ensureIndex(index); if (length == (long)bits.length << LOG2_BITS_PER_WORD) bits = LongArrays.grow(bits, numWords(length + 1)); length++; if (index == length - 1) set(index, value); else { final int word = word(index); final int bit = bit(index); boolean carry = (bits[word] & LAST_BIT_MASK) != 0, nextCarry; long t = bits[word]; if (bit == LAST_BIT) t &= ~LAST_BIT_MASK; else t = (t & - (1L << bit)) << 1 | t & (1L << bit) - 1; if (value) t |= 1L << bit; bits[word] = t; final int numWords = numWords(length); for(int i = word + 1; i < numWords; i++) { nextCarry = (bits[i] & LAST_BIT_MASK) != 0; bits[i] <<= 1; if (carry) bits[i] |= 1; carry = nextCarry; } } return; }
public void add( final long index, final boolean value ) { if ( CHECKS ) ensureIndex( index ); if ( length == bits.length << LOG2_BITS_PER_WORD ) bits = LongArrays.grow( bits, numWords( length + 1 ) ); length++; if ( index == length - 1 ) set( index, value ); else { final int word = word( index ); final int bit = bit( index ); boolean carry = ( bits[ word ] & LAST_BIT_MASK ) != 0, nextCarry; long t = bits[ word ]; if ( bit == LAST_BIT ) t &= ~LAST_BIT_MASK; else t = ( t & - ( 1L << bit ) ) << 1 | t & ( 1L << bit ) - 1; if ( value ) t |= 1L << bit; bits[ word ] = t; final int numWords = numWords( length ); for( int i = word + 1; i < numWords; i++ ) { nextCarry = ( bits[ i ] & LAST_BIT_MASK ) != 0; bits[ i ] <<= 1; if ( carry ) bits[ i ] |= 1; carry = nextCarry; } } return; }
public void add( final long index, final boolean value ) { if ( CHECKS ) ensureIndex( index ); if ( length == bits.length << LOG2_BITS_PER_WORD ) bits = LongArrays.grow( bits, numWords( length + 1 ) ); length++; if ( index == length - 1 ) set( index, value ); else { final int word = word( index ); final int bit = bit( index ); boolean carry = ( bits[ word ] & LAST_BIT_MASK ) != 0, nextCarry; long t = bits[ word ]; if ( bit == LAST_BIT ) t &= ~LAST_BIT_MASK; else t = ( t & - ( 1L << bit ) ) << 1 | t & ( 1L << bit ) - 1; if ( value ) t |= 1L << bit; bits[ word ] = t; final int numWords = numWords( length ); for( int i = word + 1; i < numWords; i++ ) { nextCarry = ( bits[ i ] & LAST_BIT_MASK ) != 0; bits[ i ] <<= 1; if ( carry ) bits[ i ] |= 1; carry = nextCarry; } } return; }
length = a[b].length; if (n % ratio == 0) { p = LongArrays.grow(p, n / ratio + 1); p[n / ratio] = curSize; array = IntBigArrays.grow(array, curSize + count(length) + length, curSize);
length = a[b].length; if (n % ratio == 0) { p = LongArrays.grow(p, n / ratio + 1); p[n / ratio] = curSize; array = ShortBigArrays.grow(array, curSize + count(length) + length, curSize);
length = a[b].length; if (n % ratio == 0) { p = LongArrays.grow(p, n / ratio + 1); p[n / ratio] = curSize; array = ByteBigArrays.grow(array, curSize + count(length) + length, curSize);
length = a[b].length; if (n % ratio == 0) { p = LongArrays.grow(p, n / ratio + 1); p[n / ratio] = curSize; array = CharBigArrays.grow(array, curSize + count(length) + length, curSize);
length = a[b].length; if (n % ratio == 0) { p = LongArrays.grow(p, n / ratio + 1); p[n / ratio] = curSize; array = LongBigArrays.grow(array, curSize + count(length) + length, curSize);
visit.visit(i); final int maxDistance = visit.maxDistance(); if (count.length <= maxDistance) count = LongArrays.grow(count, maxDistance + 1); for(int d = maxDistance + 1; d-- != 0;) count[d] += visit.cutPoints.getInt(d + 1) - visit.cutPoints.getInt(d); if (pl != null) pl.update();