public abstract class Page<K,V>
extends java.lang.Object
implements java.lang.Cloneable
For b-tree nodes, the key at a given index is larger than the largest key of the child at the same index.
Serialized format: length of a serialized page in bytes (including this field): int check value: short page number (0-based sequential number within a chunk): varInt map id: varInt number of keys: varInt type: byte (0: leaf, 1: node; +2: compressed) children of the non-leaf node (1 more than keys) compressed: bytes saved (varInt) keys values of the leaf node (one for each key)
| Modifier and Type | Class and Description |
|---|---|
static class |
Page.PageReference<K,V>
A pointer to a page, either in-memory or using a page position.
|
| Modifier and Type | Field and Description |
|---|---|
MVMap<K,V> |
map
Map this page belongs to
|
int |
pageNo
Sequential 0-based number of the page within containing chunk.
|
| Modifier and Type | Method and Description |
|---|---|
protected int |
calculateMemory()
Calculate estimated memory used in persistent case.
|
protected Page<K,V> |
clone() |
Page<K,V> |
copy()
Create a copy of this page.
|
K[] |
createKeyStorage(int size)
Create array for keys storage.
|
static <K,V> Page<K,V> |
createNode(MVMap<K,V> map,
K[] keys,
Page.PageReference<K,V>[] children,
long totalCount,
int memory)
Create a new non-leaf page.
|
static <K,V> Page.PageReference<K,V>[] |
createRefStorage(int size)
Create an array of page references.
|
protected void |
dump(java.lang.StringBuilder buff)
Dump debug data for this page.
|
abstract CursorPos<K,V> |
getAppendCursorPos(CursorPos<K,V> cursorPos)
Extend path from a given CursorPos chain to "append point" in a B-tree, rooted at this Page.
|
abstract Page<K,V> |
getChildPage(int index)
Get the child page at the given index.
|
abstract long |
getChildPagePos(int index)
Get the position of the child.
|
long |
getDiskSpaceUsed()
Amount of used disk space in persistent case including child pages.
|
K |
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 CursorPos<K,V> |
getPrependCursorPos(CursorPos<K,V> cursorPos)
Extend path from a given CursorPos chain to "prepend point" in a B-tree, rooted at this Page.
|
abstract int |
getRawChildPageCount() |
abstract long |
getTotalCount()
Get the total number of key-value pairs, including child pages.
|
abstract V |
getValue(int index)
Get the value at the given index.
|
abstract void |
insertLeaf(int index,
K key,
V value)
Insert a key-value pair into this leaf.
|
abstract void |
insertNode(int index,
K key,
Page<K,V> childPage)
Insert a child page into this node.
|
boolean |
isComplete() |
boolean |
isLeaf()
Check whether this is a leaf page.
|
protected boolean |
isPersistent() |
boolean |
isRemoved() |
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 int |
removeAllRecursive(long version)
Remove all page data recursively.
|
int |
removePage(long version)
Make accounting changes (chunk occupancy or "unsaved" RAM), related to
this page removal.
|
abstract void |
setChild(int index,
Page<K,V> c)
Replace the child page.
|
void |
setComplete()
Called when done with copying page.
|
void |
setKey(int index,
K key)
Replace the key at an index in this page.
|
abstract V |
setValue(int index,
V value)
Replace the value at an index in this page.
|
java.lang.String |
toString() |
protected int |
write(Chunk chunk,
WriteBuffer buff,
java.util.List<java.lang.Long> toc)
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.
|
public int pageNo
public static <K,V> Page<K,V> createNode(MVMap<K,V> map, K[] keys, Page.PageReference<K,V>[] children, long totalCount, int memory)
K - the key classV - the value classmap - the mapkeys - the keyschildren - the child page positionstotalCount - the total number of keysmemory - the memory used in bytespublic final int getMapId()
public K getKey(int index)
index - the indexpublic abstract Page<K,V> getChildPage(int index)
index - the indexpublic abstract long getChildPagePos(int index)
index - the indexpublic abstract V getValue(int index)
index - the indexpublic final int getKeyCount()
public final boolean isLeaf()
public abstract int getNodeType()
public final long getPos()
public java.lang.String toString()
toString in class java.lang.Objectprotected void dump(java.lang.StringBuilder buff)
buff - append bufferpublic abstract long getTotalCount()
public abstract void setChild(int index,
Page<K,V> c)
index - the indexc - the new child pagepublic final void setKey(int index,
K key)
index - the indexkey - the new keypublic abstract V setValue(int index, V value)
index - the indexvalue - the new valuepublic abstract void insertLeaf(int index,
K key,
V value)
index - the indexkey - the keyvalue - the valuepublic abstract void insertNode(int index,
K key,
Page<K,V> childPage)
index - the indexkey - the keychildPage - the child pagepublic void remove(int index)
index - the indexprotected abstract void readPayLoad(java.nio.ByteBuffer buff)
buff - the bufferpublic final boolean isSaved()
public final boolean isRemoved()
protected final int write(Chunk chunk, WriteBuffer buff, java.util.List<java.lang.Long> toc)
chunk - the chunkbuff - the target buffertoc - prospective table of contentprotected abstract void writeValues(WriteBuffer buff)
buff - the target bufferprotected abstract void writeChildren(WriteBuffer buff, boolean withCounts)
buff - the target bufferwithCounts - true if the descendant counts should be writtenpublic abstract int getRawChildPageCount()
protected final boolean isPersistent()
public final int getMemory()
public long getDiskSpaceUsed()
protected int calculateMemory()
public boolean isComplete()
public void setComplete()
public final int removePage(long version)
version - at which page was removedpublic abstract CursorPos<K,V> getPrependCursorPos(CursorPos<K,V> cursorPos)
cursorPos - presumably pointing to this Page (null if real root), to build uponpublic abstract CursorPos<K,V> getAppendCursorPos(CursorPos<K,V> cursorPos)
cursorPos - presumably pointing to this Page (null if real root), to build uponpublic abstract int removeAllRecursive(long version)
version - at which page got removedpublic final K[] createKeyStorage(int size)
size - number of entriespublic static <K,V> Page.PageReference<K,V>[] createRefStorage(int size)
K - the key classV - the value classsize - the number of entries