public class HTreeMap<K,V> extends AbstractMap<K,V> implements ConcurrentMap<K,V>, Bind.MapWithModificationListener<K,V>
ConcurrentHashMap
Modifier and Type | Class and Description |
---|---|
protected static class |
HTreeMap.ExpireLinkNode |
protected static class |
HTreeMap.ExpireRunnable |
protected class |
HTreeMap.KeySet |
protected static class |
HTreeMap.LinkedNode<K,V>
node which holds key-value pair
|
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Modifier and Type | Field and Description |
---|---|
protected static int |
BUCKET_OVERFLOW |
protected CountDownLatch |
closeLatch |
protected Runnable |
closeListener |
protected Atomic.Long |
counter |
protected static Serializer<long[][]> |
DIR_SERIALIZER |
protected static int |
DIV8 |
protected Engine |
engine |
protected long |
expire |
protected long |
expireAccess |
protected boolean |
expireAccessFlag |
protected boolean |
expireFlag |
protected long[] |
expireHeads |
protected long |
expireMaxSize |
protected boolean |
expireMaxSizeFlag |
protected long |
expireStoreSize |
protected long[] |
expireTails |
protected long |
expireTimeStart |
protected Hasher<K> |
hasher |
protected int |
hashSalt
Salt added to hash before rehashing, so it is harder to trigger hash collision attack.
|
protected boolean |
hasValues
is this a Map or Set? if false, entries do not have values, only keys are allowed
|
protected Serializer<K> |
keySerializer |
protected Serializer<HTreeMap.LinkedNode<K,V>> |
LN_SERIALIZER |
protected static int |
MOD8 |
protected Bind.MapListener<K,V>[] |
modListeners |
protected Object |
modListenersLock |
protected ReentrantReadWriteLock[] |
segmentLocks |
protected long[] |
segmentRecids
list of segments, this is immutable
|
protected Fun.Function1<V,K> |
valueCreator |
protected Serializer<V> |
valueSerializer |
Constructor and Description |
---|
HTreeMap(Engine engine,
long counterRecid,
int hashSalt,
long[] segmentRecids,
Serializer<K> keySerializer,
Serializer<V> valueSerializer,
long expireTimeStart,
long expire,
long expireAccess,
long expireMaxSize,
long expireStoreSize,
long[] expireHeads,
long[] expireTails,
Fun.Function1<V,K> valueCreator,
Hasher hasher,
boolean disableLocks)
Opens HTreeMap
|
Modifier and Type | Method and Description |
---|---|
void |
clear() |
void |
close()
Closes underlying storage and releases all resources.
|
boolean |
containsKey(Object o) |
boolean |
containsValue(Object value) |
Set<Map.Entry<K,V>> |
entrySet() |
protected void |
expireCheckSegment(int segment) |
protected void |
expireLinkAdd(int segment,
long expireNodeRecid,
long keyRecid,
int hash) |
protected void |
expireLinkBump(int segment,
long nodeRecid,
boolean access) |
protected HTreeMap.ExpireLinkNode |
expireLinkRemove(int segment,
long nodeRecid) |
protected HTreeMap.ExpireLinkNode |
expireLinkRemoveLast(int segment) |
protected void |
expirePurge() |
protected void |
expirePurgeSegment(int seg,
long removePerSegment) |
V |
get(Object o) |
Engine |
getEngine() |
protected HTreeMap.LinkedNode<K,V> |
getInner(Object o,
int h,
int segment) |
long |
getMaxExpireTime()
Returns maximal (newest) expiration timestamp
|
long |
getMinExpireTime()
Returns minimal (oldest) expiration timestamp
|
V |
getPeek(Object key)
Return given value, without updating cache statistics if `expireAccess()` is true
It also does not use `valueCreator` if value is not found (always returns null if not found)
|
protected int |
hash(Object key) |
boolean |
isEmpty() |
Set<K> |
keySet() |
void |
modificationListenerAdd(Bind.MapListener<K,V> listener)
Add new modification listener notified when Map has been updated
|
void |
modificationListenerRemove(Bind.MapListener<K,V> listener)
Remove registered notification listener
|
protected void |
notify(K key,
V oldValue,
V newValue) |
protected static long[] |
preallocateSegments(Engine engine) |
V |
put(K key,
V value) |
V |
putIfAbsent(K key,
V value) |
V |
remove(Object key) |
boolean |
remove(Object key,
Object value) |
protected V |
removeInternal(Object key,
int segment,
int h,
boolean removeExpire) |
V |
replace(K key,
V value) |
boolean |
replace(K key,
V oldValue,
V newValue) |
int |
size() |
long |
sizeLong() |
Map<K,V> |
snapshot()
Make readonly snapshot view of current Map.
|
Collection<V> |
values() |
finalize, getClass, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, replaceAll
protected static final int BUCKET_OVERFLOW
protected static final int DIV8
protected static final int MOD8
protected final boolean hasValues
protected final int hashSalt
protected final Atomic.Long counter
protected final Serializer<K> keySerializer
protected final Serializer<V> valueSerializer
protected final Engine engine
protected final boolean expireFlag
protected final long expireTimeStart
protected final long expire
protected final boolean expireAccessFlag
protected final long expireAccess
protected final long expireMaxSize
protected final long expireStoreSize
protected final boolean expireMaxSizeFlag
protected final long[] expireHeads
protected final long[] expireTails
protected final Fun.Function1<V,K> valueCreator
protected final CountDownLatch closeLatch
protected final Runnable closeListener
protected final Serializer<HTreeMap.LinkedNode<K,V>> LN_SERIALIZER
protected static final Serializer<long[][]> DIR_SERIALIZER
protected final long[] segmentRecids
protected final ReentrantReadWriteLock[] segmentLocks
protected final Object modListenersLock
protected Bind.MapListener<K,V>[] modListeners
public HTreeMap(Engine engine, long counterRecid, int hashSalt, long[] segmentRecids, Serializer<K> keySerializer, Serializer<V> valueSerializer, long expireTimeStart, long expire, long expireAccess, long expireMaxSize, long expireStoreSize, long[] expireHeads, long[] expireTails, Fun.Function1<V,K> valueCreator, Hasher hasher, boolean disableLocks)
protected static long[] preallocateSegments(Engine engine)
public boolean containsKey(Object o)
containsKey
in interface Map<K,V>
containsKey
in class AbstractMap<K,V>
public int size()
public long sizeLong()
sizeLong
in interface Bind.MapWithModificationListener<K,V>
public boolean isEmpty()
public V getPeek(Object key)
key
- key to lookupprotected HTreeMap.LinkedNode<K,V> getInner(Object o, int h, int segment)
public void clear()
public boolean containsValue(Object value)
containsValue
in interface Map<K,V>
containsValue
in class AbstractMap<K,V>
public Collection<V> values()
protected int hash(Object key)
public V putIfAbsent(K key, V value)
putIfAbsent
in interface ConcurrentMap<K,V>
putIfAbsent
in interface Map<K,V>
protected void expireLinkAdd(int segment, long expireNodeRecid, long keyRecid, int hash)
protected void expireLinkBump(int segment, long nodeRecid, boolean access)
protected HTreeMap.ExpireLinkNode expireLinkRemoveLast(int segment)
protected HTreeMap.ExpireLinkNode expireLinkRemove(int segment, long nodeRecid)
public long getMaxExpireTime()
public long getMinExpireTime()
protected void expirePurge()
protected void expirePurgeSegment(int seg, long removePerSegment)
protected void expireCheckSegment(int segment)
public Map<K,V> snapshot()
Maintaining snapshot have some overhead, underlying Engine is closed after Map view is GCed. Please make sure to release reference to this Map view, so snapshot view can be garbage collected.
public void modificationListenerAdd(Bind.MapListener<K,V> listener)
Bind.MapWithModificationListener
modificationListenerAdd
in interface Bind.MapWithModificationListener<K,V>
listener
- callback interface notified when map changespublic void modificationListenerRemove(Bind.MapListener<K,V> listener)
Bind.MapWithModificationListener
modificationListenerRemove
in interface Bind.MapWithModificationListener<K,V>
listener
- callback interface notified when map changespublic void close()
public Engine getEngine()
Copyright © 2017. All rights reserved.