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 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.
  • Constructor Details

    • LazyHashMap

      public LazyHashMap()
      Creates a new LazyHashMap with a default maximum segment size of 1000.
    • LazyHashMap

      public LazyHashMap​(int maxSegmentSize)
      Creates a new LazyHashMap 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

      public LazyHashMap​(int maxSegmentSize, LazySegmentUnloader lazySegmentUnloader)
      Creates a new LazyHashMap 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

      public LazyHashMap​(LazyHashMap<K,​V> map)
      Creates a new copy from the supplied LazyHashMap.
      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

      public Iterable<? extends LazyHashMap.Segment<?>> 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 this LazyArrayList.
      Returns:
      the maximum segment size of this LazyArrayList
    • hash

      protected int hash​(Object key)
      Hash function used in that map implementation.
      Parameters:
      key - Object to calculate the has for.
      Returns:
      hash.
    • size

      public int size()
      Specified by:
      size in interface Map<K,​V>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Map<K,​V>
    • containsKey

      public boolean containsKey​(Object key)
      Specified by:
      containsKey in interface Map<K,​V>
    • containsValue

      public boolean containsValue​(Object value)
      Specified by:
      containsValue in interface Map<K,​V>
    • get

      public V get​(Object key)
      Specified by:
      get in interface Map<K,​V>
    • put

      public V put​(K key, V value)
      Specified by:
      put in interface Map<K,​V>
    • remove

      public V remove​(Object key)
      Specified by:
      remove in interface Map<K,​V>
    • replace

      public V replace​(K key, V value)
      Specified by:
      replace in interface Map<K,​V>
    • replace

      public boolean replace​(K key, V oldValue, V newValue)
      Specified by:
      replace in interface Map<K,​V>
    • putAll

      public void putAll​(Map<? extends K,​? extends V> m)
      Specified by:
      putAll in interface Map<K,​V>
    • clear

      public void clear()
      Specified by:
      clear in interface Map<K,​V>
    • keySet

      public LazySet<K> keySet()
      Specified by:
      keySet in interface Map<K,​V>
    • values

      public LazyCollection<V> values()
      Specified by:
      values in interface Map<K,​V>
    • entrySet

      public LazySet<Map.Entry<K,​V>> entrySet()
      Specified by:
      entrySet in interface Map<K,​V>
    • toString

      public String 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.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this map.
    • link

      public void link​(ObjectSwizzling objectLoader)
      Links the map to a ObjectSwizzling instance.
      Parameters:
      objectLoader - ObjectSwizzling instance.
    • verifyLoader

      public void verifyLoader​(ObjectSwizzling objectLoader)
      Throws an IllegalStateException if the current loader is not null and is not the provided one.
      Parameters:
      objectLoader - to be verified.