Package one.microstream.collections.lazy
Class LazyHashMap<K,V>
java.lang.Object
one.microstream.collections.lazy.LazyHashMap<K,V>
- Type Parameters:
K- Type of keys.V- Type of values.
- All Implemented Interfaces:
Map<K,V>
public final class LazyHashMap<K,V> extends Object implements Map<K,V>
This map implementation internally uses
Internally the key value pairs are kept in segments that are controlled by
This implementation requires an active microstream storage with specialized type handlers. Without those handles a correct behavior is not guaranteed. The required handlers are: BinaryHandlerLazyHashMap BinaryHandlerLazyHashMapSegmentEntryList BinaryHandlerControlledLazy
The Map gets bound to a specific storage instance at the first store. After the map has been persisted the first time it is no more possible to persist it to a different storage. In that case an IllegalStateException is thrown.
Lazy references internally,
to enable automatic partial loading of it's content.
Internally the key value pairs are kept in segments that are controlled by
Lazy references. The maxSegmentSize define the maximal desired number of
key / value pairs to be kept in a single segment. When loading data all elements of a segment
are loaded.
In case of hash collisions a
segment may exceed that desired maxSegmentSize. Key / value entries are sorted
ascending by the keys hash values.
This implementation requires an active microstream storage with specialized type handlers. Without those handles a correct behavior is not guaranteed. The required handlers are: BinaryHandlerLazyHashMap BinaryHandlerLazyHashMapSegmentEntryList BinaryHandlerControlledLazy
The Map gets bound to a specific storage instance at the first store. After the map has been persisted the first time it is no more possible to persist it to a different storage. In that case an IllegalStateException is thrown.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLazyHashMap.Entry<K,V>static classLazyHashMap.LazyHashMapSegmentEntryList<K,V>classLazyHashMap.Segment<E extends LazyHashMap.Entry<K,V>> -
Constructor Summary
Constructors Constructor Description LazyHashMap()Creates a newLazyHashMapwith a default maximum segment size of 1000.LazyHashMap(int maxSegmentSize)Creates a newLazyHashMapwith a maximum desired segment size.LazyHashMap(int maxSegmentSize, LazySegmentUnloader lazySegmentUnloader)Creates a newLazyHashMapwith a maximum desired segment size.LazyHashMap(LazyHashMap<K,V> map)Creates a new copy from the suppliedLazyHashMap. -
Method Summary
Modifier and Type Method Description voidclear()booleancontainsKey(Object key)booleancontainsValue(Object value)LazySet<Map.Entry<K,V>>entrySet()Vget(Object key)intgetMaxSegmentSize()Returns the maximum segment size of thisLazyArrayList.longgetSegmentCount()Returns the current number of internal segments.protected inthash(Object key)Hash function used in that map implementation.booleanisEmpty()LazySet<K>keySet()voidlink(ObjectSwizzling objectLoader)Links the map to aObjectSwizzlinginstance.Vput(K key, V value)voidputAll(Map<? extends K,? extends V> m)Vremove(Object key)Vreplace(K key, V value)booleanreplace(K key, V oldValue, V newValue)Iterable<? extends LazyHashMap.Segment<?>>segments()Returns an Iterable over the Segment in this list.intsize()StringtoString()Returns the string representation of this map.LazyCollection<V>values()voidverifyLoader(ObjectSwizzling objectLoader)Throws an IllegalStateException if the current loader is not null and is not the provided one.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replaceAll
-
Constructor Details
-
LazyHashMap
public LazyHashMap()Creates a newLazyHashMapwith a default maximum segment size of 1000. -
LazyHashMap
public LazyHashMap(int maxSegmentSize)Creates a newLazyHashMapwith a maximum desired segment size. The desired maximum segment size is not a hard limit. The map may exceed that limit.- Parameters:
maxSegmentSize- maximum desired segment size, must be non negative.
-
LazyHashMap
Creates a newLazyHashMapwith a maximum desired segment size. The desired maximum segment size is not a hard limit. The map may exceed that limit.- Parameters:
maxSegmentSize- maximum desired segment size, must be non negative.lazySegmentUnloader- LazySegmentUnloader instance
-
LazyHashMap
Creates a new copy from the suppliedLazyHashMap.
The key and value Objects of the source map will not be copied, both maps will reference the same key and value object instances.- Parameters:
map- to be copied.
-
-
Method Details
-
getSegmentCount
public long getSegmentCount()Returns the current number of internal segments.- Returns:
- the current number of internal segments.
-
segments
Returns an Iterable over the Segment in this list.- Returns:
- an Iterable over the Segment in this list
-
getMaxSegmentSize
public int getMaxSegmentSize()Returns the maximum segment size of thisLazyArrayList.- Returns:
- the maximum segment size of this
LazyArrayList
-
hash
Hash function used in that map implementation.- Parameters:
key- Object to calculate the has for.- Returns:
- hash.
-
size
public int size() -
isEmpty
public boolean isEmpty() -
containsKey
- Specified by:
containsKeyin interfaceMap<K,V>
-
containsValue
- Specified by:
containsValuein interfaceMap<K,V>
-
get
-
put
-
remove
-
replace
-
replace
-
putAll
-
clear
public void clear() -
keySet
-
values
-
entrySet
-
toString
Returns the string representation of this map. Key-value pairs will be coded as 'key'='value'. They are grouped by the internal segments. If internal segments are unloaded they will not get loaded, the key-value pairs stored in those segments will not be included in the returned string. Unloaded segments just report the number of unloaded contained elements. -
link
Links the map to aObjectSwizzlinginstance.- Parameters:
objectLoader- ObjectSwizzling instance.
-
verifyLoader
Throws an IllegalStateException if the current loader is not null and is not the provided one.- Parameters:
objectLoader- to be verified.
-