private static void insertKeyValueNoLock(long[] table, int capacity, long item1, long item2) { int bucket = signSafeMod(hash(item1, item2), capacity); while (true) { long storedKey = table[bucket]; if (storedKey == EmptyItem) { // The bucket is empty, so we can use it table[bucket] = item1; table[bucket + 1] = item2; return; } bucket = (bucket + 2) & (table.length - 1); } } }
private boolean remove(long item1, long item2, int hash) { long stamp = writeLock(); int bucket = signSafeMod(hash, capacity); try { while (true) { long storedItem1 = table[bucket]; long storedItem2 = table[bucket + 1]; if (item1 == storedItem1 && item2 == storedItem2) { --size; cleanBucket(bucket); return true; } else if (storedItem1 == EmptyItem) { return false; } bucket = (bucket + 2) & (table.length - 1); } } finally { unlockWrite(stamp); } }
boolean contains(long item1, long item2, int hash) { long stamp = tryOptimisticRead(); boolean acquiredLock = false; int bucket = signSafeMod(hash, capacity); acquiredLock = true; bucket = signSafeMod(hash, capacity); storedItem1 = table[bucket]; storedItem2 = table[bucket + 1];
boolean add(long item1, long item2, long hash) { long stamp = writeLock(); int bucket = signSafeMod(hash, capacity);
private static void insertKeyValueNoLock(long[] table, int capacity, long item1, long item2) { int bucket = signSafeMod(hash(item1, item2), capacity); while (true) { long storedKey = table[bucket]; if (storedKey == EmptyItem) { // The bucket is empty, so we can use it table[bucket] = item1; table[bucket + 1] = item2; return; } bucket = (bucket + 2) & (table.length - 1); } } }
boolean contains(long item1, long item2, int hash) { long stamp = tryOptimisticRead(); boolean acquiredLock = false; int bucket = signSafeMod(hash, capacity); acquiredLock = true; bucket = signSafeMod(hash, capacity); storedItem1 = table[bucket]; storedItem2 = table[bucket + 1];
private boolean remove(long item1, long item2, int hash) { long stamp = writeLock(); int bucket = signSafeMod(hash, capacity); try { while (true) { long storedItem1 = table[bucket]; long storedItem2 = table[bucket + 1]; if (item1 == storedItem1 && item2 == storedItem2) { --size; cleanBucket(bucket); return true; } else if (storedItem1 == EmptyItem) { return false; } bucket = (bucket + 2) & (table.length - 1); } } finally { unlockWrite(stamp); } }
boolean add(long item1, long item2, long hash) { long stamp = writeLock(); int bucket = signSafeMod(hash, capacity);