private void rehash() { // Expand the hashmap int newCapacity = capacity * 2; long[] newTable = new long[newCapacity]; Arrays.fill(newTable, EmptyItem); // Re-hash table for (int i = 0; i < table.length; i++) { long storedItem = table[i]; if (storedItem != EmptyItem && storedItem != DeletedItem) { insertKeyValueNoLock(newTable, newCapacity, storedItem); } } table = newTable; usedBuckets = size; CAPACITY_UPDATER.lazySet(this, newCapacity); resizeThreshold = (int) (newCapacity * SetFillFactor); }
@SuppressWarnings("NonAtomicVolatileUpdate") boolean add(long item, long hash) { long stamp = writeLock(); int bucket = signSafeMod(hash, capacity); if (usedBuckets > resizeThreshold) { try { rehash(); } finally { unlockWrite(stamp); unlockWrite(stamp);
@SuppressWarnings("NonAtomicVolatileUpdate") boolean add(long item, long hash) { long stamp = writeLock(); int bucket = signSafeMod(hash, capacity); if (usedBuckets > resizeThreshold) { try { rehash(); } finally { unlockWrite(stamp); unlockWrite(stamp);
@SuppressWarnings("NonAtomicVolatileUpdate") boolean add(long item, long hash) { long stamp = writeLock(); int bucket = signSafeMod(hash, capacity); if (usedBuckets > resizeThreshold) { try { rehash(); } finally { unlockWrite(stamp); unlockWrite(stamp);
boolean contains(long item, int hash) { long stamp = tryOptimisticRead(); boolean acquiredLock = false; int bucket = signSafeMod(hash, capacity); if (!acquiredLock && validate(stamp)) { stamp = readLock(); acquiredLock = true; unlockRead(stamp);
@SuppressWarnings("NonAtomicVolatileUpdate") boolean add(long item, long hash) { long stamp = writeLock(); int bucket = signSafeMod(hash, capacity); if (usedBuckets > resizeThreshold) { try { rehash(); } finally { unlockWrite(stamp); unlockWrite(stamp);
@SuppressWarnings("NonAtomicVolatileUpdate") boolean add(long item, long hash) { long stamp = writeLock(); int bucket = signSafeMod(hash, capacity); if (usedBuckets > resizeThreshold) { try { rehash(); } finally { unlockWrite(stamp); unlockWrite(stamp);
boolean contains(long item, int hash) { long stamp = tryOptimisticRead(); boolean acquiredLock = false; int bucket = signSafeMod(hash, capacity); if (!acquiredLock && validate(stamp)) { stamp = readLock(); acquiredLock = true; unlockRead(stamp);
boolean contains(long item, int hash) { long stamp = tryOptimisticRead(); boolean acquiredLock = false; int bucket = signSafeMod(hash, capacity); if (!acquiredLock && validate(stamp)) { stamp = readLock(); acquiredLock = true; unlockRead(stamp);
boolean contains(long item, int hash) { long stamp = tryOptimisticRead(); boolean acquiredLock = false; int bucket = signSafeMod(hash, capacity); if (!acquiredLock && validate(stamp)) { stamp = readLock(); acquiredLock = true; unlockRead(stamp);
@SuppressWarnings("NonAtomicVolatileUpdate") boolean add(long item, long hash) { long stamp = writeLock(); int bucket = signSafeMod(hash, capacity); if (usedBuckets > resizeThreshold) { try { rehash(); } finally { unlockWrite(stamp); unlockWrite(stamp);
boolean contains(long item, int hash) { long stamp = tryOptimisticRead(); boolean acquiredLock = false; int bucket = signSafeMod(hash, capacity); if (!acquiredLock && validate(stamp)) { stamp = readLock(); acquiredLock = true; unlockRead(stamp);
public void forEach(ConsumerLong processor) { long stamp = tryOptimisticRead(); if (!validate(stamp)) { stamp = readLock(); acquiredReadLock = true; table = this.table; long storedItem = table[bucket]; if (!acquiredReadLock && !validate(stamp)) { stamp = readLock(); acquiredReadLock = true; unlockRead(stamp);
boolean contains(long item, int hash) { long stamp = tryOptimisticRead(); boolean acquiredLock = false; int bucket = signSafeMod(hash, capacity); if (!acquiredLock && validate(stamp)) { stamp = readLock(); acquiredLock = true; unlockRead(stamp);
public void forEach(ConsumerLong processor) { long stamp = tryOptimisticRead(); if (!validate(stamp)) { stamp = readLock(); acquiredReadLock = true; table = this.table; long storedItem = table[bucket]; if (!acquiredReadLock && !validate(stamp)) { stamp = readLock(); acquiredReadLock = true; unlockRead(stamp);
public void forEach(ConsumerLong processor) { long stamp = tryOptimisticRead(); if (!validate(stamp)) { stamp = readLock(); acquiredReadLock = true; table = this.table; long storedItem = table[bucket]; if (!acquiredReadLock && !validate(stamp)) { stamp = readLock(); acquiredReadLock = true; unlockRead(stamp);
public void forEach(ConsumerLong processor) { long stamp = tryOptimisticRead(); if (!validate(stamp)) { stamp = readLock(); acquiredReadLock = true; table = this.table; long storedItem = table[bucket]; if (!acquiredReadLock && !validate(stamp)) { stamp = readLock(); acquiredReadLock = true; unlockRead(stamp);
public void forEach(ConsumerLong processor) { long stamp = tryOptimisticRead(); if (!validate(stamp)) { stamp = readLock(); acquiredReadLock = true; table = this.table; long storedItem = table[bucket]; if (!acquiredReadLock && !validate(stamp)) { stamp = readLock(); acquiredReadLock = true; unlockRead(stamp);
public void forEach(ConsumerLong processor) { long stamp = tryOptimisticRead(); if (!validate(stamp)) { stamp = readLock(); acquiredReadLock = true; table = this.table; long storedItem = table[bucket]; if (!acquiredReadLock && !validate(stamp)) { stamp = readLock(); acquiredReadLock = true; unlockRead(stamp);
@SuppressWarnings("NonAtomicVolatileUpdate") private boolean remove(long item, int hash) { long stamp = writeLock(); int bucket = signSafeMod(hash, capacity); try { while (true) { long storedItem = table[bucket]; if (item == storedItem) { --size; cleanBucket(bucket); return true; } else if (storedItem == EmptyItem) { // Key wasn't found return false; } bucket = (bucket + 1) & (table.length - 1); } } finally { unlockWrite(stamp); } }