Page

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)

Methods
static Page create(MVMap map, long version, Object[] keys, Object[] values, Page.PageReference[] children, long totalCount, int memory)
Create a new page.
static Page create(MVMap map, long version, Object[] keys, 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
static Page create(MVMap map, long version, Page source)
Create a copy of a page.
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
static Page createEmpty(MVMap map, long version)
Create a new, empty page.
static Page createEmpty(MVMap map, long version)
Create a new, empty page.
Parameters:
map - the map
version - the version
Returns:
the new page
static Page read(FileStore fileStore, long pos, MVMap map, long filePos, long maxPos)
Read a page.
static Page read(FileStore fileStore, long pos, MVMap map, long filePos, long maxPos)
Read a page.
Parameters:
fileStore - the file store
pos - the position
map - the map
filePos - the position in the file
maxPos - the maximum position (the end of the chunk)
Returns:
the page
int binarySearch(Object key)
Search the key in this page using a binary search.
int binarySearch(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
Page copy(long version)
Create a copy of this page.
Page copy(long version)
Create a copy of this page.
Parameters:
version - the new version
Returns:
a page with the given version
boolean equals(Object other)
boolean equals(Object other)
Page getChildPage(int index)
Get the child page at the given index.
Page getChildPage(int index)
Get the child page at the given index.
Parameters:
index - the index
Returns:
the child page
long getChildPagePos(int index)
Get the position of the child.
long getChildPagePos(int index)
Get the position of the child.
Parameters:
index - the index
Returns:
the position
long getCounts(int index)
Get the descendant counts for the given child.
long getCounts(int index)
Get the descendant counts for the given child.
Parameters:
index - the child index
Returns:
the descendant count
Object getKey(int index)
Get the key at the given index.
Object getKey(int index)
Get the key at the given index.
Parameters:
index - the index
Returns:
the key
int getKeyCount()
Get the number of keys in this page.
int getKeyCount()
Get the number of keys in this page.
Returns:
the number of keys
int getMemory()
int getMemory()
long getPos()
Get the position of the page
long getPos()
Get the position of the page
Returns:
the position
int getRawChildPageCount()
int getRawChildPageCount()
long getTotalCount()
Get the total number of key-value pairs, including child pages.
long getTotalCount()
Get the total number of key-value pairs, including child pages.
Returns:
the number of key-value pairs
Object getValue(int index)
Get the value at the given index.
Object getValue(int index)
Get the value at the given index.
Parameters:
index - the index
Returns:
the value
long getVersion()
long getVersion()
int hashCode()
int hashCode()
void insertLeaf(int index, Object key, Object value)
Insert a key-value pair into this leaf.
void insertLeaf(int index, Object key, Object value)
Insert a key-value pair into this leaf.
Parameters:
index - the index
key - the key
value - the value
void insertNode(int index, Object key, Page childPage)
Insert a child page into this node.
void insertNode(int index, Object key, Page childPage)
Insert a child page into this node.
Parameters:
index - the index
key - the key
childPage - the child page
boolean isLeaf()
Check whether this is a leaf page.
boolean isLeaf()
Check whether this is a leaf page.
Returns:
true if it is a leaf
void read(ByteBuffer buff, int chunkId, int offset, int maxLength)
Read the page from the buffer.
void read(ByteBuffer buff, int chunkId, int offset, int maxLength)
Read the page from the buffer.
Parameters:
buff - the buffer
chunkId - the chunk id
offset - the offset within the chunk
maxLength - the maximum length
void remove(int index)
Remove the key and value (or child) at the given index.
void remove(int index)
Remove the key and value (or child) at the given index.
Parameters:
index - the index
void removeAllRecursive()
Remove this page and all child pages.
void removeAllRecursive()
Remove this page and all child pages.
void removePage()
Remove the page.
void removePage()
Remove the page.
void setChild(int index, Page c)
Replace the child page.
void setChild(int index, Page c)
Replace the child page.
Parameters:
index - the index
c - the new child page
void setKey(int index, Object key)
Replace the key at an index in this page.
void setKey(int index, Object key)
Replace the key at an index in this page.
Parameters:
index - the index
key - the new key
Object setValue(int index, Object value)
Replace the value at an index in this page.
Object setValue(int index, Object value)
Replace the value at an index in this page.
Parameters:
index - the index
value - the new value
Returns:
the old value
void setVersion(long version)
void setVersion(long version)
Page split(int at)
Split the page.
Page split(int at)
Split the page. This modifies the current page.
Parameters:
at - the split index
Returns:
the page with the entries after the split index
String toString()
String toString()
void writeEnd()
Unlink the children recursively after all data is written.
void writeEnd()
Unlink the children recursively after all data is written.
void writeUnsavedRecursive(Chunk chunk, WriteBuffer buff)
Store this page and all children that are changed, in reverse order, and update the position and the children.
void writeUnsavedRecursive(Chunk chunk, WriteBuffer buff)
Store this page and all children that are changed, in reverse order, and update the position and the children.
Parameters:
chunk - the chunk
buff - the target buffer

Fields
static Object[] EMPTY_OBJECT_ARRAY

EMPTY_OBJECT_ARRAY

An empty object array.