Class HTreeMap<K,V>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- org.mapdb.HTreeMap<K,V>
-
- All Implemented Interfaces:
- java.io.Closeable, java.io.Serializable, java.lang.AutoCloseable, java.util.concurrent.ConcurrentMap<K,V>, java.util.Map<K,V>, Bind.MapWithModificationListener<K,V>
public class HTreeMap<K,V> extends java.util.AbstractMap<K,V> implements java.util.concurrent.ConcurrentMap<K,V>, Bind.MapWithModificationListener<K,V>, java.io.Closeable, java.io.Serializable
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 to
ConcurrentHashMap- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description classHTreeMap.KeySet
-
Constructor Summary
Constructors Constructor and Description HTreeMap(Engine[] engines, boolean closeEngine, long[] counterRecids, 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, java.util.concurrent.ScheduledExecutorService executor, long executorPeriod, boolean closeExecutor, java.util.concurrent.locks.Lock consistencyLock)Opens HTreeMap
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidclear()voidclose()booleancontainsKey(java.lang.Object o)booleancontainsValue(java.lang.Object value)java.util.Set<java.util.Map.Entry<K,V>>entrySet()Vget(java.lang.Object o)EnginegetEngine()longgetMaxExpireTime()Returns maximal (newest) expiration timestamplonggetMinExpireTime()Returns minimal (oldest) expiration timestampVgetPeek(java.lang.Object key)Return given value, without updating cache statistics ifexpireAccess()is true It also does not usevalueCreatorif value is not found (always returns null if not found)booleanisEmpty()java.util.Set<K>keySet()longmappingCount()voidmodificationListenerAdd(Bind.MapListener<K,V> listener)Add new modification listener notified when Map has been updatedvoidmodificationListenerRemove(Bind.MapListener<K,V> listener)Remove registered notification listenerVput(K key, V value)VputIfAbsent(K key, V value)Vremove(java.lang.Object key)booleanremove(java.lang.Object key, java.lang.Object value)Vreplace(K key, V value)booleanreplace(K key, V oldValue, V newValue)intsize()longsizeLong()java.util.Map<K,V>snapshot()Make readonly snapshot view of current Map.java.util.Collection<V>values()
-
-
-
Constructor Detail
-
HTreeMap
public HTreeMap(Engine[] engines, boolean closeEngine, long[] counterRecids, 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, java.util.concurrent.ScheduledExecutorService executor, long executorPeriod, boolean closeExecutor, java.util.concurrent.locks.Lock consistencyLock)
Opens HTreeMap
-
-
Method Detail
-
containsKey
public boolean containsKey(java.lang.Object o)
-
size
public int size()
-
sizeLong
public long sizeLong()
- Specified by:
sizeLongin interfaceBind.MapWithModificationListener<K,V>- Returns:
- size of map, but in 64bit long which does not overflow at 2e9 items.
-
mappingCount
public long mappingCount()
-
isEmpty
public boolean isEmpty()
-
get
public V get(java.lang.Object o)
-
getPeek
public V getPeek(java.lang.Object key)
Return given value, without updating cache statistics ifexpireAccess()is true It also does not usevalueCreatorif value is not found (always returns null if not found)- Parameters:
key- key to lookup- Returns:
- value associated with key or null
-
remove
public V remove(java.lang.Object key)
-
clear
public void clear()
-
containsValue
public boolean containsValue(java.lang.Object value)
-
keySet
public java.util.Set<K> keySet()
-
values
public java.util.Collection<V> values()
-
remove
public boolean remove(java.lang.Object key, java.lang.Object value)
-
getMaxExpireTime
public long getMaxExpireTime()
Returns maximal (newest) expiration timestamp
-
getMinExpireTime
public long getMinExpireTime()
Returns minimal (oldest) expiration timestamp
-
snapshot
public java.util.Map<K,V> snapshot()
Make readonly snapshot view of current Map. Snapshot is immutable and not affected by modifications made by other threads. Useful if you need consistent view on Map.
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.
- Returns:
- snapshot
-
modificationListenerAdd
public void modificationListenerAdd(Bind.MapListener<K,V> listener)
Description copied from interface:Bind.MapWithModificationListenerAdd new modification listener notified when Map has been updated- Specified by:
modificationListenerAddin interfaceBind.MapWithModificationListener<K,V>- Parameters:
listener- callback interface notified when map changes
-
modificationListenerRemove
public void modificationListenerRemove(Bind.MapListener<K,V> listener)
Description copied from interface:Bind.MapWithModificationListenerRemove registered notification listener- Specified by:
modificationListenerRemovein interfaceBind.MapWithModificationListener<K,V>- Parameters:
listener- callback interface notified when map changes
-
getEngine
public Engine getEngine()
-
close
public void close()
- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfacejava.lang.AutoCloseable
-
-
DataMelt 3.0 © DataMelt by jWork.ORG