void directRemove(final Bytes keyBytes, int hash2) { lock(); try { hash2 = hashLookup.startSearch(hash2); while (true) { final int pos = hashLookup.nextPos(); if (pos < 0) { return; } else { final long offset = entriesOffset + pos * entrySize; tmpBytes.storePositionAndSize(bytes, offset, entrySize); if (!keyEquals(keyBytes, tmpBytes)) continue; final long keyLength = align(keyBytes.remaining() + tmpBytes.position()); // includes the stop bit length. tmpBytes.position(keyLength); hashLookup.remove(hash2, pos); decrementSize(); freeList.clear(pos); if (pos < nextSet) nextSet = pos; return; } } } finally { unlock(); } }
synchronized boolean remove(long hash, K key) { int h = smallMap.startSearch(hash); boolean found = false; while (true) { int pos = smallMap.nextPos(); if (pos < 0) { break; } bytes.storePositionAndSize(store, pos * smallEntrySize, smallEntrySize); K key2 = getKey(); if (equals(key, key2)) { usedSet.clear(pos); smallMap.remove(h, pos); found = true; this.size--; break; } } K key2 = key instanceof CharSequence ? (K) key.toString() : key; DirectStore remove = map.remove(key2); if (remove == null) return found; offHeapUsed -= remove.size(); remove.free(); this.size--; return true; }
/** * implementation for map.remove(Key,Value) * * @param keyBytes the key of the entry to remove * @param expectedValue the entry will only be removed if the {@param existingValue} equals null * or the {@param existingValue} equals that of the entry.value * @param hash2 a hash code relating to the {@keyBytes} ( not the natural hash of {@keyBytes} ) * @return */ V remove(final DirectBytes keyBytes, final V expectedValue, int hash2) { lock(); try { hash2 = hashLookup.startSearch(hash2); while (true) { final int pos = hashLookup.nextPos(); if (pos < 0) { return null; } else { final long offset = entriesOffset + pos * entrySize; tmpBytes.storePositionAndSize(bytes, offset, entrySize); if (!keyEquals(keyBytes, tmpBytes)) continue; final long keyLength = align(keyBytes.remaining() + tmpBytes.position()); // includes the stop bit length. tmpBytes.position(keyLength); V valueRemoved = expectedValue == null && removeReturnsNull ? null : readObjectUsing(null, offset + keyLength); if (expectedValue != null && !expectedValue.equals(valueRemoved)) return null; hashLookup.remove(hash2, pos); decrementSize(); freeList.clear(pos); if (pos < nextSet) nextSet = pos; return valueRemoved; } } } finally { unlock(); } }