private boolean removeNullEntry() { containsNull = false; key[n] = (null); size--; if (n > minN && size < maxFill / 4 && n > DEFAULT_INITIAL_SIZE) rehash(n / 2); return true; } @SuppressWarnings("unchecked")
private void ensureCapacity(final int capacity) { final int needed = arraySize(capacity, f); if (needed > n) rehash(needed); } private void tryCapacity(final long capacity) {
private boolean removeEntry(final int pos) { size--; shiftKeys(pos); if (n > minN && size < maxFill / 4 && n > DEFAULT_INITIAL_SIZE) rehash(n / 2); return true; } private boolean removeNullEntry() {
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); } @Override
return true; try { rehash(l); } catch (OutOfMemoryError cantDoIt) { return false;
/** * Rehashes this set, making the table as small as possible. * * <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> * If the table size is already the minimum possible, this method does nothing. * * @return true if there was enough memory to trim the set. * @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 (OutOfMemoryError cantDoIt) { return false; } return true; } /**
@Override public boolean add(final K k) { int pos; if ((strategy.equals((k), (null)))) { if (containsNull) return false; containsNull = true; key[n] = k; } else { K curr; final K[] key = this.key; // The starting point. if (!((curr = key[pos = (it.unimi.dsi.fastutil.HashCommon.mix(strategy.hashCode(k))) & mask]) == null)) { if ((strategy.equals((curr), (k)))) return false; while (!((curr = key[pos = (pos + 1) & mask]) == null)) if ((strategy.equals((curr), (k)))) return false; } key[pos] = k; } if (size++ >= maxFill) rehash(arraySize(size + 1, f)); if (ASSERTS) checkTable(); return true; } /**
rehash(arraySize(size + 1, f)); if (ASSERTS) checkTable();