/** * Grows this array list, ensuring that it can contain the given number of entries without * resizing, and in case enlarging it at least by a factor of two. * * @param capacity the new minimum capacity for this array list. */ @SuppressWarnings("unchecked") private void grow(final int capacity) { if (wrapped) a = ObjectArrays.grow(a, capacity, size); else { if (capacity > a.length) { final int newLength = (int) Math .max(Math.min(2L * a.length, it.unimi.dsi.fastutil.Arrays.MAX_ARRAY_SIZE), capacity); final Object t[] = new Object[newLength]; System.arraycopy(a, 0, t, 0, size); a = (K[]) t; } } if (ASSERTS) assert size <= a.length; }
/** * 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 <K> K[] grow(final K[] array, final int length) { return grow(array, length, array.length); } /**
@Override @SuppressWarnings("unchecked") public void enqueue(K x) { if (size == array.length) array = ObjectArrays.grow(array, size + 1); if (firstIndexValid) { if (c == null) { if ((((Comparable<K>) (x)).compareTo(array[firstIndex]) < 0)) firstIndex = size; } else if (c.compare(x, array[firstIndex]) < 0) firstIndex = size; } else firstIndexValid = false; array[size++] = x; } @Override
/** Grows this array list, ensuring that it can contain the given number of entries without resizing, * and in case enlarging it at least by a factor of two. * * @param capacity the new minimum capacity for this array list. */ @SuppressWarnings("unchecked") private void grow( final int capacity ) { if ( wrapped ) a = ObjectArrays.grow( a, capacity, size ); else { if ( capacity > a.length ) { final int newLength = (int)Math.max( Math.min( 2L * a.length, it.unimi.dsi.fastutil.Arrays.MAX_ARRAY_SIZE ), capacity ); final Object t[] = new Object[ newLength ]; System.arraycopy( a, 0, t, 0, size ); a = (K[])t; } } if ( ASSERTS ) assert size <= a.length; } public void add( final int index, final K k ) {
@Override public void enqueue(K x) { if (size == heap.length) heap = ObjectArrays.grow(heap, size + 1); heap[size++] = x; ObjectHeaps.upHeap(heap, size, size - 1, c); } @Override
public Boolean visit( final MultiTermIndexIterator multiTermIndexIterator ) throws IOException { indexIterator = ObjectArrays.grow( indexIterator, multiTermIndexIterator.n ); final int k = multiTermIndexIterator.front( indexIterator ); for( int i = 0; i < k; i++ ) trueTerms.add( indexIterator[ i ].term() ); return Boolean.TRUE; }
public Boolean visit( final MultiTermIndexIterator multiTermIndexIterator ) throws IOException { indexIterator = ObjectArrays.grow( indexIterator, multiTermIndexIterator.n ); final int k = multiTermIndexIterator.front( indexIterator ); for( int i = 0; i < k; i++ ) trueTerms.add( indexIterator[ i ].term() ); return Boolean.TRUE; }
/** * 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}). */ @SuppressWarnings("unchecked") public static <K> K[] unwrap(final Iterator<? extends K> i, int max) { if (max < 0) throw new IllegalArgumentException("The maximum number of elements (" + max + ") is negative"); K array[] = (K[]) new Object[16]; int j = 0; while (max-- != 0 && i.hasNext()) { if (j == array.length) array = ObjectArrays.grow(array, j + 1); array[j++] = i.next(); } return ObjectArrays.trim(array, j); } /**
public Boolean visit( final MultiTermIndexIterator multiTermIndexIterator ) throws IOException { indexIterator = ObjectArrays.grow( indexIterator, multiTermIndexIterator.n ); final int k = multiTermIndexIterator.front( indexIterator ); for( int i = 0; i < k; i++ ) trueTerms.add( indexIterator[ i ].term() ); return Boolean.TRUE; }
public Boolean visit( final MultiTermIndexIterator multiTermIndexIterator ) throws IOException { indexIterator = ObjectArrays.grow( indexIterator, multiTermIndexIterator.n ); final int k = multiTermIndexIterator.front( indexIterator ); for( int i = 0; i < k; i++ ) trueTerms.add( indexIterator[ i ].term() ); return Boolean.TRUE; }
@Override public int nextInt() { final int curr = underlyingNodeIterator.nextInt(); final int d = underlyingNodeIterator.outdegree(); // Store all labels of arcs going out of the current node if (label.length < d) { label = ObjectArrays.grow(label, d); for(int i = label.length; i-- != 0 && label[i] == null;) label[i] = prototype.copy(); } try { for(int i = 0; i < d; i++) label[i].fromBitStream(ibs, curr); } catch (IOException e) { throw new RuntimeException(e); } return curr; }
/** Creates a new mutable graph copying a given immutable graph. * * <p>This method will not invoke {@link ImmutableGraph#numNodes()}, but rather just create a {@link NodeIterator} and exhaust it. * * @param g an immutable graph. */ public ArrayListMutableGraph(final ImmutableGraph g) { this(); int d, s = -1; long numArcs = 0; for(NodeIterator nodeIterator = g.nodeIterator(); nodeIterator.hasNext();) { s = nodeIterator.nextInt(); d = nodeIterator.outdegree(); numArcs += d; successors = ObjectArrays.grow(successors, s + 1); successors[s] = new IntArrayList(nodeIterator.successorArray(), 0, d); } n = s + 1; m = numArcs; }
if (ASSERTS) assert s0 >= 0 || s1 >= 0; cache = IntArrays.grow(cache, outdegree + 1); labelCache = ObjectArrays.grow(labelCache, outdegree + 1); if (s1 < 0 || 0 <= s0 && s0 < s1) { cache[outdegree] = s0;
if (ASSERTS) assert s0 >= 0 || s1 >= 0; cache = IntArrays.grow(cache, outdegree + 1); labelCache = ObjectArrays.grow(labelCache, outdegree + 1); if (s1 < 0 || 0 <= s0 && s0 < s1) { cache[outdegree] = s0;