private void internalInit(int capacity) { initSlotCounts(capacity); allocateArrays(capacity); }
@Override public boolean shrink() { int newCapacity = targetCapacity(size); if (removedSlots > 0 || newCapacity < capacity()) { rehash(newCapacity); return true; } else { return false; } }
@Override public void clear() { super.clear(); Object[] tab = table; for (int i = 0; i < tab.length; i += 2) { tab[i] = FREE; tab[i + 1] = null; } }
final void postRemovedSlotInsertHook() { if (++size > maxSize) { if (tryRehashForExpansion(grownCapacity())) return; } removedSlots--; }
private boolean tryRehashForExpansion(int newCapacity) { // No sense in rehashing for expansion if we already reached Java array // size limit. if (newCapacity > capacity() || removedSlots > 0) { rehash(newCapacity); return true; } else { if (freeSlots < minFreeSlots) minFreeSlots = (freeSlots + 1) / 2; return false; } }
/** * 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)); }
private void initSlotCounts(int capacity) { maxSize = maxSize(capacity); minFreeSlots = minFreeSlots(capacity, size, hashConfig().getMaxLoad(), maxSize); int freeSlots = this.freeSlots = capacity - size; // free could be less than minFreeSlots only in case when capacity // is not sufficient to comply load factor (due to saturation with // Java array size limit). Set minFreeSlots to a half of free to avoid // too often (instant) rehashing in this case. if (freeSlots < minFreeSlots) this.minFreeSlots = (freeSlots + 1) / 2; removedSlots = 0; }
private boolean tryRehashIfTooFewFreeSlots() { if (removedSlots > 0) { rehash(targetCapacity(size)); return true; } else { return tryRehashForExpansion(grownCapacity()); } }
void move(ParallelKVObjQHash hash) { super.copy(hash); table = hash.table(); }
final void init(HashConfigWrapper configWrapper, int size, short freeValue , short removedValue) { this.freeValue = freeValue; this.removedValue = removedValue; // calls allocateArrays, fill keys with this.freeValue => assign it before super.init(configWrapper, size); }
final void postFreeSlotInsertHook() { if (++size > maxSize) { if (tryRehashForExpansion(grownCapacity())) return; } if (--freeSlots < minFreeSlots) { if (!tryRehashIfTooFewFreeSlots() && freeSlots == 0) { throw new HashOverflowException(); } } }
private int grownCapacity() { return nearestGreaterCapacity(configWrapper.grow(capacity()), size, doubleSizedArrays()); } }
/** * Empties the hash. */ @Override public void clear() { modCount++; size = 0; freeSlots = capacity(); removedSlots = 0; }
private int targetCapacity(int size) { return QHashCapacities.capacity(configWrapper, size, doubleSizedArrays()); }
/** * This method just increments modification count (see {@link #modCount()}) * and calls {@link #internalInit(int)}. Should be called by subclasses in * {@link #rehash(int)} implementation. */ final void initForRehash(int newCapacity) { modCount++; internalInit(newCapacity); }
private void initSlotCounts(int capacity) { maxSize = maxSize(capacity); minFreeSlots = minFreeSlots(capacity, size, hashConfig().getMaxLoad(), maxSize); int freeSlots = this.freeSlots = capacity - size; // free could be less than minFreeSlots only in case when capacity // is not sufficient to comply load factor (due to saturation with // Java array size limit). Set minFreeSlots to a half of free to avoid // too often (instant) rehashing in this case. if (freeSlots < minFreeSlots) this.minFreeSlots = (freeSlots + 1) / 2; removedSlots = 0; }
private boolean tryRehashIfTooFewFreeSlots() { if (removedSlots > 0) { rehash(targetCapacity(size)); return true; } else { return tryRehashForExpansion(grownCapacity()); } }
void copy(SeparateKVObjQHash hash) { super.copy(hash); set = hash.keys().clone(); }
final void init(HashConfigWrapper configWrapper, int size, byte freeValue , byte removedValue) { this.freeValue = freeValue; this.removedValue = removedValue; // calls allocateArrays, fill keys with this.freeValue => assign it before super.init(configWrapper, size); }
final void postFreeSlotInsertHook() { if (++size > maxSize) { if (tryRehashForExpansion(grownCapacity())) return; } if (--freeSlots < minFreeSlots) { if (!tryRehashIfTooFewFreeSlots() && freeSlots == 0) { throw new HashOverflowException(); } } }