Class Page
- java.lang.Object
-
- org.dizitart.no2.mvstore.compat.v1.mvstore.Page
-
- All Implemented Interfaces:
Cloneable
public abstract class Page extends Object implements 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 Modifier and Type Class Description static class
Page.PageReference
A pointer to a page, either in-memory or using a page position.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Page
copy()
Create a copy of this page.static Page
createNode(MVMap<?,?> map, Object[] keys, Page.PageReference[] children, long totalCount, int memory)
Create a new non-leaf page.boolean
equals(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.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 mapint
getMemory()
abstract int
getNodeType()
long
getPos()
Get the position of the pageabstract 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 Object
getValue(int index)
Get the value at the given index.int
hashCode()
abstract void
insertLeaf(int index, Object key, Object value)
Insert a key-value pair into this leaf.abstract void
insertNode(int index, Object key, Page childPage)
Insert a child page into this node.boolean
isComplete()
boolean
isLeaf()
Check whether this is a leaf page.boolean
isRemoved()
boolean
isSaved()
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, Object key)
Replace the key at an index in this page.abstract Object
setValue(int index, Object value)
Replace the value at an index in this page.String
toString()
-
-
-
Field Detail
-
map
public final MVMap<?,?> map
Map this page belongs to
-
-
Method Detail
-
createNode
public static Page createNode(MVMap<?,?> map, Object[] keys, Page.PageReference[] children, long totalCount, int memory)
Create a new non-leaf page. The arrays are not cloned.- Parameters:
map
- the mapkeys
- the keyschildren
- the child page positionstotalCount
- the total number of keysmemory
- 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 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
-
getChildPagePos
public abstract long getChildPagePos(int index)
Get the position of the child.- Parameters:
index
- the index- Returns:
- the position
-
getValue
public abstract 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
-
copy
public final Page copy()
Create a copy of this page.- Returns:
- a mutable copy of this page
-
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 indexc
- the new child page
-
setKey
public final void setKey(int index, Object key)
Replace the key at an index in this page.- Parameters:
index
- the indexkey
- the new key
-
setValue
public abstract Object setValue(int index, Object value)
Replace the value at an index in this page.- Parameters:
index
- the indexvalue
- the new value- Returns:
- the old value
-
insertLeaf
public abstract void insertLeaf(int index, Object key, Object value)
Insert a key-value pair into this leaf.- Parameters:
index
- the indexkey
- the keyvalue
- the value
-
insertNode
public abstract void insertNode(int index, Object key, Page childPage)
Insert a child page into this node.- Parameters:
index
- the indexkey
- the keychildPage
- the child page
-
remove
public void remove(int index)
Remove the key and value (or child) at the given index.- Parameters:
index
- the index
-
isSaved
public final boolean isSaved()
-
isRemoved
public final boolean isRemoved()
-
getRawChildPageCount
public abstract int getRawChildPageCount()
-
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
-
isComplete
public boolean isComplete()
-
setComplete
public void setComplete()
Called when done with copying page.
-
removePage
public final int removePage(long version)
Make accounting changes (chunk occupancy or "unsaved" RAM), related to this page removal.- Parameters:
version
- at which page was removed- Returns:
- amount (negative), by which "unsaved memory" should be adjusted, if page is unsaved one, and 0 for page that was already saved, or in case of non-persistent map
-
getPrependCursorPos
public abstract CursorPos getPrependCursorPos(CursorPos cursorPos)
Extend path from a given CursorPos chain to "prepend point" in a B-tree, rooted at this Page.- Parameters:
cursorPos
- presumably pointing to this Page (null if real root), to build upon- Returns:
- new head of the CursorPos chain
-
getAppendCursorPos
public abstract CursorPos getAppendCursorPos(CursorPos cursorPos)
Extend path from a given CursorPos chain to "append point" in a B-tree, rooted at this Page.- Parameters:
cursorPos
- presumably pointing to this Page (null if real root), to build upon- Returns:
- new head of the CursorPos chain
-
removeAllRecursive
public abstract int removeAllRecursive(long version)
Remove all page data recursively.- Parameters:
version
- at which page got removed- Returns:
- adjustment for "unsaved memory" amount
-
-