## org.h2.dev.store.btree
Class MVMap<K,V>

    java.lang.Object
      java.util.AbstractMap<K,V>
          org.h2.dev.store.btree.MVMap<K,V>

Type Parameters:
  `K` - the key class
  `V` - the value class

All Implemented Interfaces:
  java.util.Map<K,V>

Direct Known Subclasses:
  MVRTreeMap, SequenceMap

    public class MVMap<K,V>

extends java.util.AbstractMap<K,V>

A stored map.

Nested Class Summary

Nested classes/interfaces inherited from class java.util.AbstractMap
`java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>`

Nested classes/interfaces inherited from interface java.util.Map
`java.util.Map.Entry<K,V>`

Field Summary
`protected Page` `root` The root page (may not be null).
`protected MVStore` `store` The store.

Constructor Summary
`protected` `MVMap(MVStore store, int id, java.lang.String name, DataType keyType, DataType valueType, long createVersion)`

Method Summary
`protected java.lang.Object` `binarySearch(Page p, java.lang.Object key)` Get the value for the given key, or null if not found.
`protected Page` `binarySearchPage(Page p, java.lang.Object key)` Get the value for the given key, or null if not found.
`java.util.Iterator<K>` `changeIterator(long minVersion)` Iterate over all keys in changed pages.
`protected void` `checkOpen()` Check whether the map is open.
`protected void` `checkWrite()` Check whether writing is allowed.
`void` `clear()` Remove all entries.
`void` `close()` Close the map, making it read only and release the memory.
`boolean` `containsKey(java.lang.Object key)`
`java.util.Set<java.util.Map.Entry<K,V>>` `entrySet()`
`boolean` `equals(java.lang.Object o)`
`V` `get(java.lang.Object key)` Get a value.
`protected Page` `getPage(K key)` Get the page for the given value.
`Page` `getRoot()` Get the root page.
`long` `getSize()`
`int` `hashCode()`
`boolean` `hasUnsavedChanges()` Check whether this map has any unsaved changes.
`boolean` `isClosed()`
`boolean` `isReadOnly()`
`java.util.Iterator<K>` `keyIterator(K from)` Iterate over all keys.
`java.util.Set<K>` `keySet()`
`protected CursorPos` `min(Page p, Cursor<K,V> cursor, java.lang.Object key)` Go to the first element for the given key.
`protected java.lang.Object` `nextKey(CursorPos p, Cursor<K,V> cursor)` Get the next key.
`MVMap<K,V>` `openVersion(long version)` Open an old version for the given map.
`V` `put(K key, V value)` Add or replace a key-value pair.
`protected java.lang.Object` `put(Page p, long writeVersion, java.lang.Object key, java.lang.Object value)` Add or update a key-value pair.
`V` `remove(java.lang.Object key)` Remove a key-value pair, if the key exists.
`protected java.lang.Object` `remove(Page p, long writeVersion, java.lang.Object key)` Remove a key-value pair.
`void` `removeMap()` Remove all entries, and close the map.
`protected void` `removePage(Page p)` Remove the given page (make the space available).
`void` `setReadOnly(boolean readOnly)`
`protected void` `setRoot(Page newRoot)`
`int` `size()`
`java.lang.String` `toString()`

Methods inherited from class java.util.AbstractMap
`clone, containsValue, isEmpty, putAll, values`

Methods inherited from class java.lang.Object
`finalize, getClass, notify, notifyAll, wait, wait, wait`

Field Detail

### store

    protected final MVStore store

  The store.

### root

    protected Page root

  The root page (may not be null).

Constructor Detail

### MVMap

    protected MVMap(MVStore store,
                    int id,
                    java.lang.String name,
                    DataType keyType,
                    DataType valueType,
                    long createVersion)

Method Detail

### put

    public V put(K key,
                 V value)

  Add or replace a key-value pair.

  Specified by:
    `put` in interface `java.util.Map<K,V>`
  Overrides:
    `put` in class `java.util.AbstractMap<K,V>`
  Parameters:
    `key` - the key (may not be null)
    `value` - the value (may not be null)
  Returns:
    the old value if the key existed, or null otherwise

### put

    protected java.lang.Object put(Page p,
                                   long writeVersion,
                                   java.lang.Object key,
                                   java.lang.Object value)

  Add or update a key-value pair.

  Parameters:
    `p` - the page
    `writeVersion` - the write version
    `key` - the key (may not be null)
    `value` - the value (may not be null)
  Returns:
    the old value, or null

### get

    public V get(java.lang.Object key)

  Get a value.

  Specified by:
    `get` in interface `java.util.Map<K,V>`
  Overrides:
    `get` in class `java.util.AbstractMap<K,V>`
  Parameters:
    `key` - the key
  Returns:
    the value, or null if not found

### min

    protected CursorPos min(Page p,
                            Cursor<K,V> cursor,
                            java.lang.Object key)

  Go to the first element for the given key.

  Parameters:
    `p` - the current page
    `cursor` - the cursor
    `key` - the key
  Returns:
    the cursor position

### nextKey

    protected java.lang.Object nextKey(CursorPos p,
                                       Cursor<K,V> cursor)

  Get the next key.

  Parameters:
    `p` - the cursor position
    `cursor` - the cursor
  Returns:
    the next key

### binarySearch

    protected java.lang.Object binarySearch(Page p,
                                            java.lang.Object key)

  Get the value for the given key, or null if not found.

  Parameters:
    `p` - the page
    `key` - the key
  Returns:
    the value or null

### containsKey

    public boolean containsKey(java.lang.Object key)

  Specified by:
    `containsKey` in interface `java.util.Map<K,V>`
  Overrides:
    `containsKey` in class `java.util.AbstractMap<K,V>`

### getPage

    protected Page getPage(K key)

  Get the page for the given value.

  Parameters:
    `key` - the key
  Returns:
    the value, or null if not found

### binarySearchPage

    protected Page binarySearchPage(Page p,
                                    java.lang.Object key)

  Get the value for the given key, or null if not found.

  Parameters:
    `p` - the parent page
    `key` - the key
  Returns:
    the page or null

### clear

    public void clear()

  Remove all entries.

  Specified by:
    `clear` in interface `java.util.Map<K,V>`
  Overrides:
    `clear` in class `java.util.AbstractMap<K,V>`

### removeMap

    public void removeMap()

  Remove all entries, and close the map.

### close

    public void close()

  Close the map, making it read only and release the memory.

### isClosed

    public boolean isClosed()

### remove

    public V remove(java.lang.Object key)

  Remove a key-value pair, if the key exists.

  Specified by:
    `remove` in interface `java.util.Map<K,V>`
  Overrides:
    `remove` in class `java.util.AbstractMap<K,V>`
  Parameters:
    `key` - the key (may not be null)
  Returns:
    the old value if the key existed, or null otherwise

### remove

    protected java.lang.Object remove(Page p,
                                      long writeVersion,
                                      java.lang.Object key)

  Remove a key-value pair.

  Parameters:
    `p` - the page (may not be null)
    `writeVersion` - the write version
    `key` - the key
  Returns:
    the old value, or null if the key did not exist

### setRoot

    protected void setRoot(Page newRoot)

### hasUnsavedChanges

    public boolean hasUnsavedChanges()

  Check whether this map has any unsaved changes.

  Returns:
    true if there are unsaved changes.

### keyIterator

    public java.util.Iterator<K> keyIterator(K from)

  Iterate over all keys.

  Parameters:
    `from` - the first key to return
  Returns:
    the iterator

### changeIterator

    public java.util.Iterator<K> changeIterator(long minVersion)

  Iterate over all keys in changed pages. This does not include deleted deleted pages.

  Parameters:
    `minVersion` - the minimum version
  Returns:
    the iterator

### entrySet

    public java.util.Set<java.util.Map.Entry<K,V>> entrySet()

  Specified by:
    `entrySet` in interface `java.util.Map<K,V>`
  Specified by:
    `entrySet` in class `java.util.AbstractMap<K,V>`

### keySet

    public java.util.Set<K> keySet()

  Specified by:
    `keySet` in interface `java.util.Map<K,V>`
  Overrides:
    `keySet` in class `java.util.AbstractMap<K,V>`

### getRoot

    public Page getRoot()

  Get the root page.

  Returns:
    the root page

### setReadOnly

    public void setReadOnly(boolean readOnly)

### isReadOnly

    public boolean isReadOnly()

### checkOpen

    protected void checkOpen()

  Check whether the map is open.

  Throws:
    `java.lang.IllegalStateException` - if the map is closed

### checkWrite

    protected void checkWrite()

  Check whether writing is allowed.

  Throws:
    `java.lang.IllegalStateException` - if the map is read-only

### toString

    public java.lang.String toString()

  Overrides:
    `toString` in class `java.util.AbstractMap<K,V>`

### hashCode

    public int hashCode()

  Specified by:
    `hashCode` in interface `java.util.Map<K,V>`
  Overrides:
    `hashCode` in class `java.util.AbstractMap<K,V>`

### equals

    public boolean equals(java.lang.Object o)

  Specified by:
    `equals` in interface `java.util.Map<K,V>`
  Overrides:
    `equals` in class `java.util.AbstractMap<K,V>`

### size

    public int size()

  Specified by:
    `size` in interface `java.util.Map<K,V>`
  Overrides:
    `size` in class `java.util.AbstractMap<K,V>`

### getSize

    public long getSize()

### removePage

    protected void removePage(Page p)

  Remove the given page (make the space available).

  Parameters:
    `p` - the page

### openVersion

    public MVMap<K,V> openVersion(long version)

  Open an old version for the given map.

  Parameters:
    `version` - the version
  Returns:
    the map