org.h2.mvstore
Class Page

java.lang.Object
  extended by org.h2.mvstore.Page

public class Page
extends java.lang.Object

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
static class Page.PageChildren
          Contains information about which other pages are referenced (directly or indirectly) by the given page.
static class Page.PageReference
          A pointer to a page, either in-memory or using a page position.
 
Field Summary
static java.lang.Object[] EMPTY_OBJECT_ARRAY
          An empty object array.
 
Method Summary
 int binarySearch(java.lang.Object key)
          Search the key in this page using a binary search.
 Page copy(long version)
          Create a copy of this page.
static Page create(MVMap<?,?> map, long version, java.lang.Object[] keys, java.lang.Object[] values, Page.PageReference[] children, long totalCount, int memory)
          Create a new page.
static Page create(MVMap<?,?> map, long version, Page source)
          Create a copy of a page.
 boolean equals(java.lang.Object other)
           
 Page getChildPage(int index)
          Get the child page at the given index.
 long getChildPagePos(int index)
          Get the position of the child.
 java.lang.Object getKey(int index)
          Get the key at the given index.
 int getKeyCount()
          Get the number of keys in this page.
 int getMemory()
           
 long getPos()
          Get the position of the page
 int getRawChildPageCount()
           
 long getTotalCount()
          Get the total number of key-value pairs, including child pages.
 java.lang.Object getValue(int index)
          Get the value at the given index.
 int hashCode()
           
 void insertLeaf(int index, java.lang.Object key, java.lang.Object value)
          Insert a key-value pair into this leaf.
 void insertNode(int index, java.lang.Object key, Page childPage)
          Insert a child page into this node.
 boolean isLeaf()
          Check whether this is a leaf page.
 void remove(int index)
          Remove the key and value (or child) at the given index.
 void removePage()
          Remove the page.
 void setChild(int index, Page c)
          Replace the child page.
 void setKey(int index, java.lang.Object key)
          Replace the key at an index in this page.
 java.lang.Object setValue(int index, java.lang.Object value)
          Replace the value at an index in this page.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY_OBJECT_ARRAY

public static final java.lang.Object[] EMPTY_OBJECT_ARRAY
An empty object array.

Method Detail

create

public static Page create(MVMap<?,?> map,
                          long version,
                          java.lang.Object[] keys,
                          java.lang.Object[] values,
                          Page.PageReference[] children,
                          long totalCount,
                          int memory)
Create a new page. The arrays are not cloned.

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

create

public static Page create(MVMap<?,?> map,
                          long version,
                          Page source)
Create a copy of a page.

Parameters:
map - the map
version - the version
source - the source page
Returns:
the page

getKey

public java.lang.Object getKey(int index)
Get the key at the given index.

Parameters:
index - the index
Returns:
the key

getChildPage

public Page getChildPage(int index)
Get the child page at the given index.

Parameters:
index - the index
Returns:
the child page

getChildPagePos

public long getChildPagePos(int index)
Get the position of the child.

Parameters:
index - the index
Returns:
the position

getValue

public java.lang.Object getValue(int index)
Get the value at the given index.

Parameters:
index - the index
Returns:
the value

getKeyCount

public int getKeyCount()
Get the number of keys in this page.

Returns:
the number of keys

isLeaf

public boolean isLeaf()
Check whether this is a leaf page.

Returns:
true if it is a leaf

getPos

public long getPos()
Get the position of the page

Returns:
the position

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

copy

public Page copy(long version)
Create a copy of this page.

Parameters:
version - the new version
Returns:
a page with the given version

binarySearch

public int binarySearch(java.lang.Object key)
Search the key in this page using a binary search. Instead of always starting the search in the middle, the last found index is cached.

If the key was found, the returned value is the index in the key array. If not found, the returned value is negative, where -1 means the provided key is smaller than any keys in this page. See also Arrays.binarySearch.

Parameters:
key - the key
Returns:
the value or null

getTotalCount

public long getTotalCount()
Get the total number of key-value pairs, including child pages.

Returns:
the number of key-value pairs

setChild

public void setChild(int index,
                     Page c)
Replace the child page.

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

setKey

public 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 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 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 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

getRawChildPageCount

public int getRawChildPageCount()

equals

public boolean equals(java.lang.Object other)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

getMemory

public int getMemory()

removePage

public void removePage()
Remove the page.