public abstract class Page
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.
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)
| Modifier and Type | Class and Description |
|---|---|
static class |
Page.PageReference
A pointer to a page, either in-memory or using a page position.
|
| Modifier and Type | Field and Description |
|---|---|
MVMap<?,?> |
map
Map this page belongs to
|
| Modifier and Type | Method and Description |
|---|---|
protected int |
calculateMemory()
Calculate estimated memory used in persistent case.
|
protected Page |
clone() |
Page |
copy()
Create a copy of this 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)
Extend path from a given CursorPos chain 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 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 CursorPos |
getPrependCursorPos(CursorPos 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 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 |
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 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.
|
public final MVMap<?,?> map
public static Page createNode(MVMap<?,?> map, java.lang.Object[] keys, Page.PageReference[] children, long totalCount, int memory)
map - the mapkeys - the keyschildren - the child page positionstotalCount - the total number of keysmemory - the memory used in bytespublic final int getMapId()
public java.lang.Object getKey(int index)
index - the indexpublic abstract Page getChildPage(int index)
index - the indexpublic abstract long getChildPagePos(int index)
index - the indexpublic abstract java.lang.Object 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 final Page copy()
protected final Page clone()
clone in class java.lang.Objectpublic abstract long getTotalCount()
public abstract void setChild(int index,
Page c)
index - the indexc - the new child pagepublic final void setKey(int index,
java.lang.Object key)
index - the indexkey - the new keypublic abstract java.lang.Object setValue(int index,
java.lang.Object value)
index - the indexvalue - the new valuepublic abstract void insertLeaf(int index,
java.lang.Object key,
java.lang.Object value)
index - the indexkey - the keyvalue - the valuepublic abstract void insertNode(int index,
java.lang.Object key,
Page 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)
chunk - the chunkbuff - the target bufferprotected 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()
public final boolean equals(java.lang.Object other)
equals in class java.lang.Objectpublic final int hashCode()
hashCode in class java.lang.Objectprotected 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 getPrependCursorPos(CursorPos cursorPos)
cursorPos - presumably pointing to this Page (null if real root), to build uponpublic abstract CursorPos getAppendCursorPos(CursorPos cursorPos)
cursorPos - presumably pointing to this Page (null if real root), to build uponpublic abstract int removeAllRecursive(long version)
version - at which page got removed