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 class
LazyHashMap.Entry<K,V>
static class
LazyHashMap.LazyHashMapSegmentEntryList<K,V>
class
LazyHashMap.Segment<E extends LazyHashMap.Entry<K,V>>
-
Constructor Summary
Constructors Constructor Description LazyHashMap()
Creates a newLazyHashMap
with a default maximum segment size of 1000.LazyHashMap(int maxSegmentSize)
Creates a newLazyHashMap
with a maximum desired segment size.LazyHashMap(int maxSegmentSize, LazySegmentUnloader lazySegmentUnloader)
Creates a newLazyHashMap
with a maximum desired segment size.LazyHashMap(LazyHashMap<K,V> map)
Creates a new copy from the suppliedLazyHashMap
. -
Method Summary
Modifier and Type Method Description void
clear()
boolean
containsKey(Object key)
boolean
containsValue(Object value)
LazySet<Map.Entry<K,V>>
entrySet()
V
get(Object key)
int
getMaxSegmentSize()
Returns the maximum segment size of thisLazyArrayList
.long
getSegmentCount()
Returns the current number of internal segments.protected int
hash(Object key)
Hash function used in that map implementation.boolean
isEmpty()
LazySet<K>
keySet()
void
link(ObjectSwizzling objectLoader)
Links the map to aObjectSwizzling
instance.V
put(K key, V value)
void
putAll(Map<? extends K,? extends V> m)
V
remove(Object key)
V
replace(K key, V value)
boolean
replace(K key, V oldValue, V newValue)
Iterable<? extends LazyHashMap.Segment<?>>
segments()
Returns an Iterable over the Segment in this list.int
size()
String
toString()
Returns the string representation of this map.LazyCollection<V>
values()
void
verifyLoader(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, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replaceAll
-
Constructor Details
-
LazyHashMap
public LazyHashMap()Creates a newLazyHashMap
with a default maximum segment size of 1000. -
LazyHashMap
public LazyHashMap(int maxSegmentSize)Creates a newLazyHashMap
with 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 newLazyHashMap
with 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:
containsKey
in interfaceMap<K,V>
-
containsValue
- Specified by:
containsValue
in 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 aObjectSwizzling
instance.- 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.
-