private V lookupUsing(K key, V value, boolean create) { if (!kClass.isInstance(key)) return null; DirectBytes bytes = getKeyAsBytes(key); long hash = longHashCode(bytes); int segmentNum = (int) (hash & (segments.length - 1)); int hash2 = (int) (hash >>> segmentBits); return segments[segmentNum].acquire(bytes, value, hash2, create); }
private V put0(K key, V value, boolean replaceIfPresent) { if (!kClass.isInstance(key)) return null; DirectBytes bytes = getKeyAsBytes(key); long hash = longHashCode(bytes); int segmentNum = (int) (hash & (segments.length - 1)); int hash2 = (int) (hash >>> segmentBits); return segments[segmentNum].put(bytes, value, hash2, replaceIfPresent); }
private V put0(K key, V value, boolean replaceIfPresent) { if (!kClass.isInstance(key)) return null; DirectBytes bytes = getKeyAsBytes(key); long hash = longHashCode(bytes); int segmentNum = (int) (hash & (builder.segments() - 1)); int hash2 = (int) (hash / builder.segments()); // System.out.println("[" + key + "] s: " + segmentNum + " h2: " + hash2); return segments[segmentNum].put(bytes, value, hash2, replaceIfPresent); }
private V removeUsing(Object key, V value) { if (!kClass.isInstance(key)) return null; DirectBytes bytes = getKeyAsBytes((K) key); long hash = longHashCode(bytes); int segmentNum = (int) (hash & (builder.segments() - 1)); int hash2 = (int) (hash / builder.segments()); // System.out.println("[" + key + "] s: " + segmentNum + " h2: " + hash2); return segments[segmentNum].remove(bytes, value, hash2); }
/** * replace the value in a map, only if the existing entry equals {@param existingValue} * * @param key the key into the map * @param existingValue the expected existing value in the map ( could be null when we don't wish * to do this check ) * @param newValue the new value you wish to store in the map * @return the value that was replaced */ private V replaceIfValueIs(@NotNull final K key, final V existingValue, final V newValue) { if (!kClass.isInstance(key)) return null; final DirectBytes bytes = getKeyAsBytes(key); final long hash = longHashCode(bytes); final int segmentNum = (int) (hash & (segments.length - 1)); int hash2 = (int) (hash >>> segmentBits); return segments[segmentNum].replace(bytes, existingValue, newValue, hash2); }
/** * removes ( if there exists ) an entry from the map, if the {@param key} and {@param * expectedValue} match that of a maps.entry. If the {@param expectedValue} equals null then ( if * there exists ) an entry whose key equals {@param key} this is removed. * * @param key the key of the entry to remove * @param expectedValue null if not required * @return true if and entry was removed */ private V removeIfValueIs(final Object key, final V expectedValue) { if (!kClass.isInstance(key)) return null; final DirectBytes bytes = getKeyAsBytes((K) key); final long hash = longHashCode(bytes); final int segmentNum = (int) (hash & (segments.length - 1)); int hash2 = (int) (hash >>> segmentBits); return segments[segmentNum].remove(bytes, expectedValue, hash2); }
/** {@inheritDoc} */ @Override public boolean containsKey(final Object key) { if (!kClass.isInstance(key)) return false; final DirectBytes bytes = getKeyAsBytes((K) key); final long hash = longHashCode(bytes); final int segmentNum = (int) (hash & (segments.length - 1)); int hash2 = (int) (hash >>> segmentBits); return segments[segmentNum].containsKey(bytes, hash2); }