private void ensureCapacity(final int capacity) { final int needed = arraySize(capacity, f); if (needed > n) rehash(needed); } private void tryCapacity(final long capacity) {
private void tryCapacity(final long capacity) { final int needed = (int) Math.min( 1 << 30, Math.max(2, HashCommon.nextPowerOfTwo((long) Math.ceil(capacity / f)))); if (needed > n) rehash(needed); } private int removeEntry(final int pos) {
/** * Rehashes this map if the table is too large. * <p> * <P>Let <var>N</var> be the smallest table size that can hold <code>max(n,{@link #size()})</code> entries, still satisfying the load factor. If the current table size is smaller than or equal to * <var>N</var>, this method does nothing. Otherwise, it rehashes this map in a table of size <var>N</var>. * <p> * <P>This method is useful when reusing maps. {@linkplain #clear() Clearing a map} leaves the table size untouched. If you are reusing a map many times, you can call this method with a typical * size to avoid keeping around a very large table just because of a few large transient maps. * * @param n the threshold for the trimming. * @return true if there was enough memory to trim the map. * @see #trim() */ public boolean trim(final int n) { final int l = HashCommon.nextPowerOfTwo((int) Math.ceil(n / f)); if (l >= n || size > maxFill(l, f)) return true; try { rehash(l); } catch (Exception cantDoIt) { return false; } return true; }
/** * Rehashes the map, making the table as small as possible. * <p> * <P>This method rehashes the table to the smallest size satisfying the load factor. It can be used when the set will not be changed anymore, so to optimize access speed and size. * <p> * <P>If the table size is already the minimum possible, this method does nothing. * * @return true if there was enough memory to trim the map. * @see #trim(int) */ public boolean trim() { final int l = arraySize(size, f); if (l >= n || size > maxFill(l, f)) return true; try { rehash(l); } catch (Exception cantDoIt) { return false; } return true; }
private int removeNullEntry() { containsNullKey = false; key[n] = null; final IntVLA oldValue = value[n]; final int popped = oldValue.pop(); if(oldValue.size == 0) --size; fixOrder(n); fixValues(); if (oldValue.size == 0 && size < (maxFill >>> 2) && n > DEFAULT_INITIAL_SIZE) rehash(n / 2); return popped; }
private int removeEntry(final int pos) { final IntVLA oldValue = value[pos]; final int popped = oldValue.pop(); if(oldValue.size == 0) --size; fixOrder(pos); shiftKeys(pos); fixValues(); if (oldValue.size == 0 && size < (maxFill >>> 2) && n > DEFAULT_INITIAL_SIZE) rehash(n / 2); return popped; } private int removeNullEntry() {
value[pos].add(at); if (size++ >= maxFill) rehash(arraySize(size + 1, f)); return -1;