Reduces the size of the backing arrays to be the specified capacity or less. If the capacity is already less, nothing is
done. If the map contains more items than the specified capacity, the next highest power of two capacity is used instead.
431960
public void shrink (int maximumCapacity) {
		if (maximumCapacity < 0) throw new IllegalArgumentException("maximumCapacity must be >= 0: " + maximumCapacity);
		if (size > maximumCapacity) maximumCapacity = size;
		if (capacity <= maximumCapacity) return;
		maximumCapacity = nextPowerOfTwo(maximumCapacity);
		resize(maximumCapacity);
	}
918051
public void ensureCapacity(int size) {
    if (size > elements.length) {
      reallocate(Math.max(size, 2 * elements.length));
    }
  }
242937
def resize(self, capacity):
        
        count = max(int(capacity), 0) - len(self)

        if count == 0:
            pass
        elif -count == len(self):
            self.clear()
        elif count > 0:
            for i in range(count):
                self.append()
        else:
            for i in range(abs(count)):
                self.pop()
1323981
private boolean resize(int newCapacity) {
        // assert (newCapacity & -newCapacity) == newCapacity; // power of 2
        int newLength = newCapacity * 2;

        Object[] oldTable = table;
        int oldLength = oldTable.length;
        if (oldLength == 2 * MAXIMUM_CAPACITY) { // can't expand any further
            if (size == MAXIMUM_CAPACITY - 1)
                throw new IllegalStateException("Capacity exhausted.");
            return false;
        }
        if (oldLength >= newLength)
            return false;

        Object[] newTable = new Object[newLength];

        for (int j = 0; j < oldLength; j += 2) {
            Object key = oldTable[j];
            if (key != null) {
                Object value = oldTable[j+1];
                oldTable[j] = null;
                oldTable[j+1] = null;
                int i = hash(key, newLength);
                while (newTable[i] != null)
                    i = nextKeyIndex(i, newLength);
                newTable[i] = key;
                newTable[i + 1] = value;
            }
        }
        table = newTable;
        return true;
    }
1096195
private void ensureCapacity(int wordsRequired)
  {
    if (words.length >= wordsRequired) {
      return;
    }
    int newLength = Math.max(words.length << 1, wordsRequired);
    words = Arrays.copyOf(words, newLength);
  }
292873
public void ensureCapacity (int additionalCapacity) {
		int sizeNeeded = size + additionalCapacity;
		if (sizeNeeded >= threshold) resize(ObjectMap.nextPowerOfTwo((int)(sizeNeeded / loadFactor)));
	}
984945
public void trimToSize() {
		this.modCount++;
		final int oldCapacity = this.data.length;
		if (this.size < oldCapacity) {
			this.data = Arrays.copyOf(this.data, this.size);
		}
	}
447797
boolean ensureInputCapacity(int capacity) {
        return signature.successors.ensureCapacity(capacity) | signature.outputs.ensureCapacity(capacity);
    }
282315
private static void shrinkHeap(TreeSet<DoubleDBIDPair> hotset, int k) {
    // drop duplicates
    ModifiableDBIDs seenids = DBIDUtil.newHashSet(2 * k);
    int cnt = 0;
    for(Iterator<DoubleDBIDPair> i = hotset.iterator(); i.hasNext();) {
      DoubleDBIDPair p = i.next();
      if(cnt > k || seenids.contains(p)) {
        i.remove();
      }
      else {
        seenids.add(p);
        cnt++;
      }
    }
  }
862571
protected void resize(int new_length) {
        if(keys == null) {
            keys=new byte[Math.min(new_length, 0xff)][];
            values=new byte[Math.min(new_length, 0xff)][];
            return;
        }
        if(new_length > 0xff) {
            if(keys.length < 0xff)
                new_length=0xff;
            else
                throw new ArrayIndexOutOfBoundsException("the hashmap cannot exceed " + 0xff + " entries");
        }

        keys=Arrays.copyOf(keys, new_length);
        values=Arrays.copyOf(values, new_length);
    }
582707
protected void resize(int newCapacity) {
        parent = Arrays.copyOf(parent, newCapacity);
        left = Arrays.copyOf(left, newCapacity);
        right = Arrays.copyOf(right, newCapacity);
        depth = Arrays.copyOf(depth, newCapacity);
    }
1342512
private int calculateCapacity(int minimumCapacity) {
    int newCapacity = Math.min(Math.max(capacity, 2), minimumCapacity);
    while (newCapacity < Math.min(minimumCapacity, maxCapacity)) {
      newCapacity <<= 1;
    }
    return Math.min(newCapacity, maxCapacity);
  }
544125
public void trim() {
    keys = Arrays.copyOf(keys, size);
    values = Arrays.copyOf(values, size);
    for (MappeableContainer c : values) {
      c.trim();
    }
  }
1309160
public void ensureCapacity(int minimumCapacity) {
        if (mHashes.length < minimumCapacity) {
            final int[] ohashes = mHashes;
            final Object[] oarray = mArray;
            allocArrays(minimumCapacity);
            if (mSize > 0) {
                System.arraycopy(ohashes, 0, mHashes, 0, mSize);
                System.arraycopy(oarray, 0, mArray, 0, mSize);
            }
            freeArrays(ohashes, oarray, mSize);
        }
    }
187475
private SparseTensor reduceDimensions(Set<Integer> dimensionsToEliminate,
      boolean useSum, Backpointers backpointers) {
    // TODO(jayantk): This method can be generalized to support a
    // generic reduce
    // operation (as a function), but it's unclear what the effect on
    // performance will be.

    // Rotate all of the dimensions which are being eliminated to the
    // end of the keyNums array.
    int[] newLabels = new int[numDimensions()];
    int[] inversionPermutation = new int[numDimensions()];
    int[] newDimensions = new int[numDimensions()];
    int[] newDimensionSizes = new int[numDimensions()];
    int numEliminated = 0;
    int[] dimensionNums = getDimensionNumbers();
    int[] dimensionSizes = getDimensionSizes();
    for (int i = 0; i < dimensionNums.length; i++) {
      if (dimensionsToEliminate.contains(dimensionNums[i])) {
        // Dimension labels must be unique, hence numEliminated.
        newLabels[i] = Integer.MAX_VALUE - numEliminated;
        inversionPermutation[dimensionNums.length - (numEliminated + 1)] = i;
        numEliminated++;
      } else {
        newLabels[i] = dimensionNums[i];
        inversionPermutation[i - numEliminated] = i;
        newDimensions[i - numEliminated] = dimensionNums[i];
        newDimensionSizes[i - numEliminated] = dimensionSizes[i];
      }
    }

    if (numEliminated == 0) {
      // If none of the dimensions being eliminated are actually part of
      // this tensor, then there's no need to do any more work.
      if (backpointers != null) {
        backpointers.setBackpointers(keyNums, keyNums, keyNums.length, this);
      }
      return this;
    } else if (numEliminated == dimensionNums.length && backpointers == null && useSum) {
      // Faster implementation for summing up all values in the tensor,
      // a common operation.
      return sumOutAllDimensions();
    }

    SparseTensor relabeled = relabelDimensions(newLabels);
    int resultNumDimensions = dimensionNums.length - numEliminated;

    // Get a number which we can divide each key by to map it to a key
    // in the reduced dimensional tensor.
    long keyNumDenominator = (resultNumDimensions > 0) ? relabeled.indexOffsets[resultNumDimensions - 1] :
        relabeled.indexOffsets[0] * relabeled.getDimensionSizes()[0];

    long[] resultKeyInts = new long[relabeled.values.length];
    long[] backpointerKeyInts = new long[relabeled.values.length];
    double[] resultValues = new double[relabeled.values.length];

    int resultInd = 0;
    long[] relabeledKeyNums = relabeled.keyNums;
    double[] relabeledValues = relabeled.values;
    int relabeledValuesLength = relabeled.values.length;
    for (int i = 0; i < relabeledValuesLength; i++) {
      long relabeledKeyNumI = relabeledKeyNums[i];
      if (i != 0 && resultInd > 0 &&
          (relabeledKeyNumI / keyNumDenominator) == resultKeyInts[resultInd - 1]) {
        // This key maps to the same entry as the previous key.
        if (useSum) {
          resultValues[resultInd - 1] += relabeledValues[i];
        } else {
          double resultVal = resultValues[resultInd - 1];
          double relabeledVal = relabeledValues[i];
          if (relabeledVal > resultVal) {
            resultValues[resultInd - 1] = relabeledVal;
            backpointerKeyInts[resultInd - 1] = relabeledKeyNumI;
          }
        }
      } else {
        if (resultInd > 0 && resultValues[resultInd - 1] == 0.0) {
          // Make sure the result tensor contains no zero-valued
          // entries.
          resultInd--;
        }

        resultKeyInts[resultInd] = relabeledKeyNumI / keyNumDenominator;
        backpointerKeyInts[resultInd] = relabeledKeyNumI;
        resultValues[resultInd] = relabeledValues[i];
        resultInd++;
      }

      int prevIndex = resultInd - 1;
      if (!useSum && resultValues[prevIndex] < 0.0) {
        // Ensure that, if values is negative, we include missing keys
        // in the maximization.
        long prevKeyNum = relabeledKeyNumI - 1;
        long nextKeyNum = relabeledKeyNumI + 1;

        if (i > 0 && relabeledKeyNums[i - 1] != prevKeyNum
            && prevKeyNum / keyNumDenominator == resultKeyInts[prevIndex]) {
          // prevKeyNum is not in relabeled, but has a higher value
          // than the current key.
          resultValues[prevIndex] = 0.0;
          backpointerKeyInts[prevIndex] = prevKeyNum;
        } else if (i + 1 < relabeledValuesLength && relabeledKeyNums[i + 1] != nextKeyNum
            && nextKeyNum / keyNumDenominator == resultKeyInts[prevIndex]) {
          // nextKeyNum is not in relabeled, but has a higher value
          // than the current key. Delete the current key from the tensor.
          resultValues[prevIndex] = 0.0;
          backpointerKeyInts[prevIndex] = nextKeyNum;
        }
      }
    }

    if (backpointers != null) {
      // backpointerKeyInts needs to have the inverse dimension
      // relabeling applied to it.
      long[] transformedBackpointers = transformKeyNums(backpointerKeyInts, relabeled.indexOffsets,
          this.indexOffsets, inversionPermutation);
      backpointers.setBackpointers(resultKeyInts, transformedBackpointers, resultInd, this);
    }

    return resizeIntoTable(ArrayUtils.copyOf(newDimensions, resultNumDimensions),
        ArrayUtils.copyOf(newDimensionSizes, resultNumDimensions),
        resultKeyInts, resultValues, resultInd);
  }
758025
private void resizeBuf(int size)
    {
        int capacity;
        if (size >= _capacity * 2)
        {
            capacity = size;
        }
        else
        {
            capacity = 1;
            while (capacity < size)
            {
                capacity <<= 1;
            }
        }
        byte[] buf = new byte[capacity];
        if (_size > 0)
        {
            System.arraycopy(_buf, 0, buf, 0, _size);
        }
        _buf = buf;
        _capacity = capacity;
    }
281878
private void memorySizeCheck(){
		if (this.stm.numInstances() + this.ltm.numInstances() > this.maxSTMSize + this.maxLTMSize){
			if (this.ltm.numInstances() > this.maxLTMSize){
				this.clusterDown();
			}else{ //shift values from STM directly to LTM since STM is full
				int numShifts = this.maxLTMSize - this.ltm.numInstances() + 1;
				for (int i = 0; i < numShifts; i++){
					this.ltm.add(this.stm.get(0).copy());
					this.stm.delete(0);
					this.stmHistory.remove(0);
					this.ltmHistory.remove(0);
					this.cmHistory.remove(0);
				}
				this.clusterDown();
				this.predictionHistories.clear();
				for (int i = 0; i < this.stm.numInstances(); i++){
					for (int j = 0; j < this.stm.numInstances(); j++){
						this.distanceMatrixSTM[i][j] = this.distanceMatrixSTM[numShifts+i][numShifts+j];
					}
				}
			}
		}
	}