|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.util.AbstractMap<K,V>
org.mapdb.HTreeMap<K,V>
public class HTreeMap<K,V>
Thread safe concurrent HashMap
This map uses full 32bit hash from beginning, There is no initial load factor and rehash. Technically it is not hash table, but hash tree with nodes expanding when they become full. This map is suitable for number of records 1e9 and over. Larger number of records will increase hash collisions and performance will degrade linearly with number of records (separate chaining). Concurrent scalability is achieved by splitting HashMap into 16 segments, each with separate lock. Very similar toConcurrentHashMap
| Nested Class Summary | |
|---|---|
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 |
| Nested classes/interfaces inherited from class java.util.AbstractMap |
|---|
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V> |
| Nested classes/interfaces inherited from interface java.util.Map |
|---|
Map.Entry<K,V> |
| Field Summary | |
|---|---|
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 Summary | |
|---|---|
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 |
|
| Method Summary | |
|---|---|
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()
|
| Methods inherited from class java.util.AbstractMap |
|---|
clone, equals, hashCode, putAll, toString |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Map |
|---|
equals, hashCode, putAll |
| Field Detail |
|---|
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 Hasher<K> hasher
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
| Constructor Detail |
|---|
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)
| Method Detail |
|---|
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()
size in interface Map<K,V>size in class AbstractMap<K,V>public long sizeLong()
sizeLong in interface Bind.MapWithModificationListener<K,V>public boolean isEmpty()
isEmpty in interface Map<K,V>isEmpty in class AbstractMap<K,V>public V get(Object o)
get in interface Map<K,V>get in class AbstractMap<K,V>public V getPeek(Object key)
key - key to lookup
protected HTreeMap.LinkedNode<K,V> getInner(Object o,
int h,
int segment)
public V put(K key,
V value)
put in interface Map<K,V>put in class AbstractMap<K,V>public V remove(Object key)
remove in interface Map<K,V>remove in class AbstractMap<K,V>
protected V removeInternal(Object key,
int segment,
int h,
boolean removeExpire)
public void clear()
clear in interface Map<K,V>clear in class AbstractMap<K,V>public boolean containsValue(Object value)
containsValue in interface Map<K,V>containsValue in class AbstractMap<K,V>public Set<K> keySet()
keySet in interface Map<K,V>keySet in class AbstractMap<K,V>public Collection<V> values()
values in interface Map<K,V>values in class AbstractMap<K,V>public Set<Map.Entry<K,V>> entrySet()
entrySet in interface Map<K,V>entrySet in class AbstractMap<K,V>protected int hash(Object key)
public V putIfAbsent(K key,
V value)
putIfAbsent in interface ConcurrentMap<K,V>
public boolean remove(Object key,
Object value)
remove in interface ConcurrentMap<K,V>
public boolean replace(K key,
V oldValue,
V newValue)
replace in interface ConcurrentMap<K,V>
public V replace(K key,
V value)
replace in interface ConcurrentMap<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 changes
protected void notify(K key,
V oldValue,
V newValue)
public void close()
public Engine getEngine()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||