org.h2.mvstore

## Class Page

- java.lang.Object
- - org.h2.mvstore.Page

All Implemented Interfaces:
  java.lang.Cloneable

    public abstract class Page
    extends java.lang.Object
    implements java.lang.Cloneable

A page (a node or a leaf).

For b-tree nodes, the key at a given index is larger than the largest key of the child at the same index.

File format: page length (including length): int check value: short map id: varInt number of keys: varInt type: byte (0: leaf, 1: node; +2: compressed) compressed: bytes saved (varInt) keys leaf: values (one for each key) node: children (1 more than keys)

### Nested Class Summary

Nested Classes
`static class` `Page.PageReference` A pointer to a page, either in-memory or using a page position.

### Field Summary

Fields
`MVMap<?,?>` `map` Map this page belongs to

### Method Summary

Methods
`protected int` `calculateMemory()` Calculate estimated memory used in persistent case.
`protected Page` `clone()`
`Page` `copy()` Create a copy of this page.
`Page` `copy(boolean countRemoval)` Create a copy of this page.
`static Page` `createLeaf(MVMap<?,?> map, java.lang.Object[] keys, java.lang.Object[] values, int memory)` Create a new leaf page.
`static Page` `createNode(MVMap<?,?> map, java.lang.Object[] keys, Page.PageReference[] children, long totalCount, int memory)` Create a new non-leaf page.
`protected void` `dump(java.lang.StringBuilder buff)` Dump debug data for this page.
`boolean` `equals(java.lang.Object other)`
`abstract CursorPos` `getAppendCursorPos(CursorPos cursorPos)` Update given CursorPos chain to correspond to "append point" in a B-tree rooted at this Page.
`abstract Page` `getChildPage(int index)` Get the child page at the given index.
`abstract Page` `getChildPageIfLoaded(int index)` Get the child page at the given index only if is already loaded.
`abstract long` `getChildPagePos(int index)` Get the position of the child.
`long` `getDiskSpaceUsed()` Amount of used disk space in persistent case including child pages.
`java.lang.Object` `getKey(int index)` Get the key at the given index.
`int` `getKeyCount()` Get the number of keys in this page.
`int` `getMapId()` Get the id of the page's owner map
`int` `getMemory()`
`abstract int` `getNodeType()`
`long` `getPos()` Get the position of the page
`abstract int` `getRawChildPageCount()`
`abstract long` `getTotalCount()` Get the total number of key-value pairs, including child pages.
`abstract java.lang.Object` `getValue(int index)` Get the value at the given index.
`int` `hashCode()`
`abstract void` `insertLeaf(int index, java.lang.Object key, java.lang.Object value)` Insert a key-value pair into this leaf.
`abstract void` `insertNode(int index, java.lang.Object key, Page childPage)` Insert a child page into this node.
`boolean` `isComplete()`
`boolean` `isLeaf()` Check whether this is a leaf page.
`protected boolean` `isPersistent()`
`boolean` `isSaved()`
`protected abstract void` `readPayLoad(java.nio.ByteBuffer buff)` Read the page payload from the buffer.
`void` `remove(int index)` Remove the key and value (or child) at the given index.
`abstract void` `removeAllRecursive()` Remove all page data recursively.
`void` `removePage()` Remove the page.
`abstract void` `setChild(int index, Page c)` Replace the child page.
`void` `setComplete()` Called when done with copying page.
`void` `setKey(int index, java.lang.Object key)` Replace the key at an index in this page.
`abstract java.lang.Object` `setValue(int index, java.lang.Object value)` Replace the value at an index in this page.
`java.lang.String` `toString()`
`protected int` `write(Chunk chunk, WriteBuffer buff)` Store the page and update the position.
`protected abstract void` `writeChildren(WriteBuffer buff, boolean withCounts)` Write page children to the buff.
`protected abstract void` `writeValues(WriteBuffer buff)` Write values that the buffer contains to the buff.

### Methods inherited from class java.lang.Object

`finalize, getClass, notify, notifyAll, wait, wait, wait`

### Field Detail

#### map

    public final MVMap<?,?> map

Map this page belongs to

### Method Detail

#### createNode

    public static Page createNode(MVMap<?,?> map,
                  java.lang.Object[] keys,
                  Page.PageReference[] children,
                  long totalCount,
                  int memory)

Create a new non-leaf page. The arrays are not cloned.

Parameters:
  `map` - the map
  `keys` - the keys
  `children` - the child page positions
  `totalCount` - the total number of keys
  `memory` - the memory used in bytes
Returns:
  the page

#### createLeaf

    public static Page createLeaf(MVMap<?,?> map,
                  java.lang.Object[] keys,
                  java.lang.Object[] values,
                  int memory)

Create a new leaf page. The arrays are not cloned.

Parameters:
  `map` - the map
  `keys` - the keys
  `values` - the values
  `memory` - the memory used in bytes
Returns:
  the page

#### getMapId

    public final int getMapId()

Get the id of the page's owner map

Returns:
  id

#### getKey

    public java.lang.Object getKey(int index)

Get the key at the given index.

Parameters:
  `index` - the index
Returns:
  the key

#### getChildPage

    public abstract Page getChildPage(int index)

Get the child page at the given index.

Parameters:
  `index` - the index
Returns:
  the child page

#### getChildPageIfLoaded

    public abstract Page getChildPageIfLoaded(int index)

Get the child page at the given index only if is already loaded. Does not make any attempt to load the page or retrieve it from the cache.

Parameters:
  `index` - the index
Returns:
  the child page, null if it is not loaded

#### getChildPagePos

    public abstract long getChildPagePos(int index)

Get the position of the child.

Parameters:
  `index` - the index
Returns:
  the position

#### getValue

    public abstract java.lang.Object getValue(int index)

Get the value at the given index.

Parameters:
  `index` - the index
Returns:
  the value

#### getKeyCount

    public final int getKeyCount()

Get the number of keys in this page.

Returns:
  the number of keys

#### isLeaf

    public final boolean isLeaf()

Check whether this is a leaf page.

Returns:
  true if it is a leaf

#### getNodeType

    public abstract int getNodeType()

#### getPos

    public final long getPos()

Get the position of the page

Returns:
  the position

#### toString

    public java.lang.String toString()

Overrides:
  `toString` in class `java.lang.Object`

#### dump

    protected void dump(java.lang.StringBuilder buff)

Dump debug data for this page.

Parameters:
  `buff` - append buffer

#### copy

    public final Page copy()

Create a copy of this page.

Returns:
  a mutable copy of this page

#### copy

    public final Page copy(boolean countRemoval)

Create a copy of this page.

Parameters:
  `countRemoval` - When `true` the current page is removed, when `false` just copy the page.
Returns:
  a mutable copy of this page

#### clone

    protected final Page clone()

Overrides:
  `clone` in class `java.lang.Object`

#### getTotalCount

    public abstract long getTotalCount()

Get the total number of key-value pairs, including child pages.

Returns:
  the number of key-value pairs

#### setChild

    public abstract void setChild(int index,
                Page c)

Replace the child page.

Parameters:
  `index` - the index
  `c` - the new child page

#### setKey

    public final void setKey(int index,
              java.lang.Object key)

Replace the key at an index in this page.

Parameters:
  `index` - the index
  `key` - the new key

#### setValue

    public abstract java.lang.Object setValue(int index,
                            java.lang.Object value)

Replace the value at an index in this page.

Parameters:
  `index` - the index
  `value` - the new value
Returns:
  the old value

#### insertLeaf

    public abstract void insertLeaf(int index,
                  java.lang.Object key,
                  java.lang.Object value)

Insert a key-value pair into this leaf.

Parameters:
  `index` - the index
  `key` - the key
  `value` - the value

#### insertNode

    public abstract void insertNode(int index,
                  java.lang.Object key,
                  Page childPage)

Insert a child page into this node.

Parameters:
  `index` - the index
  `key` - the key
  `childPage` - the child page

#### remove

    public void remove(int index)

Remove the key and value (or child) at the given index.

Parameters:
  `index` - the index

#### readPayLoad

    protected abstract void readPayLoad(java.nio.ByteBuffer buff)

Read the page payload from the buffer.

Parameters:
  `buff` - the buffer

#### isSaved

    public final boolean isSaved()

#### write

    protected final int write(Chunk chunk,
            WriteBuffer buff)

Store the page and update the position.

Parameters:
  `chunk` - the chunk
  `buff` - the target buffer
Returns:
  the position of the buffer just after the type

#### writeValues

    protected abstract void writeValues(WriteBuffer buff)

Write values that the buffer contains to the buff.

Parameters:
  `buff` - the target buffer

#### writeChildren

    protected abstract void writeChildren(WriteBuffer buff,
                     boolean withCounts)

Write page children to the buff.

Parameters:
  `buff` - the target buffer
  `withCounts` - true if the descendant counts should be written

#### getRawChildPageCount

    public abstract int getRawChildPageCount()

#### equals

    public final boolean equals(java.lang.Object other)

Overrides:
  `equals` in class `java.lang.Object`

#### hashCode

    public final int hashCode()

Overrides:
  `hashCode` in class `java.lang.Object`

#### isPersistent

    protected final boolean isPersistent()

#### getMemory

    public final int getMemory()

#### getDiskSpaceUsed

    public long getDiskSpaceUsed()

Amount of used disk space in persistent case including child pages.

Returns:
  amount of used disk space in persistent case

#### calculateMemory

    protected int calculateMemory()

Calculate estimated memory used in persistent case.

Returns:
  memory in bytes

#### isComplete

    public boolean isComplete()

#### setComplete

    public void setComplete()

Called when done with copying page.

#### removePage

    public final void removePage()

Remove the page.

#### getAppendCursorPos

    public abstract CursorPos getAppendCursorPos(CursorPos cursorPos)

Update given CursorPos chain to correspond to "append point" in a B-tree rooted at this Page.

Parameters:
  `cursorPos` - to update, presumably pointing to this Page
Returns:
  new head of the CursorPos chain

#### removeAllRecursive

    public abstract void removeAllRecursive()

Remove all page data recursively.