/** * Creates data structures with a prime capacity at or near the minimum * needed to hold {@code size} elements without triggering a rehash. * * <p>Should be called only in constructors and externalization code. */ final void init(HashConfigWrapper configWrapper, int size) { this.configWrapper = configWrapper; this.size = 0; internalInit(targetCapacity(size)); }
/** * Creates data structures with a prime capacity at or near the minimum * needed to hold {@code size} elements without triggering a rehash. * * <p>Should be called only in constructors and externalization code. */ final void init(HashConfigWrapper configWrapper, int size) { this.configWrapper = configWrapper; this.size = 0; internalInit(targetCapacity(size)); }
@Override public final boolean ensureCapacity(long minSize) { int intMinSize = (int) Math.min(minSize, (long) Integer.MAX_VALUE); if (minSize < 0L) throw new IllegalArgumentException( "Min size should be positive, " + minSize + " given."); int additionalSize = intMinSize - size; if (additionalSize <= 0) return false; if (intMinSize > maxSize || freeSlots - additionalSize < minFreeSlots) { return tryRehashForExpansion(targetCapacity(intMinSize)); } else { return false; } }
@Override public final boolean ensureCapacity(long minSize) { int intMinSize = (int) Math.min(minSize, (long) Integer.MAX_VALUE); if (minSize < 0L) throw new IllegalArgumentException( "Min size should be positive, " + minSize + " given."); int additionalSize = intMinSize - size; if (additionalSize <= 0) return false; if (intMinSize > maxSize || freeSlots - additionalSize < minFreeSlots) { return tryRehashForExpansion(targetCapacity(intMinSize)); } else { return false; } }
@Override public boolean shrink() { int newCapacity = targetCapacity(size); if (removedSlots > 0 || newCapacity < capacity()) { rehash(newCapacity); return true; } else { return false; } }
@Override public boolean shrink() { int newCapacity = targetCapacity(size); if (removedSlots > 0 || newCapacity < capacity()) { rehash(newCapacity); return true; } else { return false; } }
private boolean tryRehashIfTooFewFreeSlots() { if (removedSlots > 0) { rehash(targetCapacity(size)); return true; } else { return tryRehashForExpansion(grownCapacity()); } }
private boolean tryRehashIfTooFewFreeSlots() { if (removedSlots > 0) { rehash(targetCapacity(size)); return true; } else { return tryRehashForExpansion(grownCapacity()); } }