K - The type for the KeyV - The type for the stored valueabstract class AbstractPage<K,V> extends java.lang.Object implements Page<K,V>
| Modifier and Type | Field and Description |
|---|---|
protected BTree<K,V> |
btree
Parent B+Tree.
|
protected PageHolder<K,V>[] |
children
Children pages associated with keys.
|
protected KeyHolder<K>[] |
keys
Keys of children nodes
|
protected long |
lastOffset
The last
PageIO storing the serialized Page on disk |
protected int |
nbElems
The number of current values in the Page
|
protected long |
offset
The first
PageIO storing the serialized Page on disk |
protected long |
revision
This BPage's revision
|
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractPage(BTree<K,V> btree)
Creates a default empty AbstractPage
|
protected |
AbstractPage(BTree<K,V> btree,
long revision,
int nbElems)
Internal constructor used to create Page instance used when a page is being copied or overflow
|
| Modifier and Type | Method and Description |
|---|---|
TupleCursor<K,V> |
browse(K key,
ReadTransaction<K,V> transaction,
ParentPos<K,V>[] stack,
int depth)
Browses the tree, looking for the given key, and creates a Cursor on top
of the found result.
|
TupleCursor<K,V> |
browse(ReadTransaction<K,V> transaction,
ParentPos<K,V>[] stack,
int depth)
Browses the whole tree, and creates a Cursor on top of it.
|
KeyCursor<K> |
browseKeys(ReadTransaction<K,K> transaction,
ParentPos<K,K>[] stack,
int depth)
Browses the keys of whole tree, and creates a Cursor on top of it.
|
protected int |
compare(K key1,
K key2)
Compares two keys
|
boolean |
contains(K key,
V value)
Checks if the page contains the given key with the given value.
|
DeleteResult<K,V> |
delete(K key,
V value,
long revision)
Deletes the value from an entry associated with the given key in this page.
|
(package private) abstract DeleteResult<K,V> |
delete(K key,
V value,
long revision,
Page<K,V> parent,
int parentPos)
The real delete implementation.
|
java.lang.String |
dumpPage(java.lang.String tabs)
Pretty-prints the tree with tabs
|
Tuple<K,V> |
findLeftMost()
Finds the leftmost element in this page.
|
int |
findPos(K key)
Finds the position of the given key in the page.
|
Tuple<K,V> |
findRightMost()
Finds the rightmost element in this page.
|
V |
get(K key)
Gets the value associated with the given key, if any.
|
BTree<K,V> |
getBtree() |
K |
getKey(int pos)
Returns the key at a given position
|
(package private) KeyHolder<K>[] |
getKeys() |
(package private) long |
getLastOffset() |
K |
getLeftMostKey()
Finds the leftmost key in this page.
|
int |
getNbElems() |
(package private) long |
getOffset() |
(package private) Page<K,V> |
getPage(int pos) |
(package private) Page<K,V> |
getReference(int pos) |
long |
getRevision() |
K |
getRightMostKey()
Finds the rightmost key in this page.
|
(package private) ValueHolder<V> |
getValue(int pos) |
ValueCursor<V> |
getValues(K key)
Gets the values associated with the given key, if any.
|
boolean |
hasKey(K key)
Checks if the given key exists.
|
protected int |
selectSibling(Page<K,V> parent,
int parentPos)
Selects the sibling (the previous or next page with the same parent) which has
the more element assuming it's above N/2
|
(package private) void |
setKey(int pos,
KeyHolder<K> key)
Sets the key at a give position
|
(package private) void |
setKeys(KeyHolder<K>[] keys) |
(package private) void |
setLastOffset(long lastOffset) |
(package private) void |
setNbElems(int nbElems)
Sets the number of element in this page
|
(package private) void |
setOffset(long offset) |
(package private) void |
setPageHolder(int pos,
PageHolder<K,V> pageHolder)
Inject a pageHolder into the node, at a given position
|
(package private) void |
setRevision(long revision) |
(package private) void |
setValue(int pos,
ValueHolder<V> value)
Sets the value at a give position
|
java.lang.String |
toString() |
protected PageHolder<K,V>[] children
protected int nbElems
protected long revision
protected long offset
PageIO storing the serialized Page on diskprotected long lastOffset
PageIO storing the serialized Page on diskprotected AbstractPage(BTree<K,V> btree)
btree - The associated BTreepublic int getNbElems()
getNbElems in interface Page<K,V>void setNbElems(int nbElems)
nbElems - The number of elementspublic K getKey(int pos)
public boolean hasKey(K key) throws java.io.IOException
public TupleCursor<K,V> browse(K key, ReadTransaction<K,V> transaction, ParentPos<K,V>[] stack, int depth) throws java.io.IOException
browse in interface Page<K,V>key - The key we are looking for.transaction - The started transaction for this operationstack - The stack of parents we go through to get to this pagejava.io.IOException - If we have an error while trying to access the pagepublic boolean contains(K key, V value) throws java.io.IOException
public DeleteResult<K,V> delete(K key, V value, long revision) throws java.io.IOException
delete in interface Page<K,V>key - The key to deletevalue - The value to delete (can be null)revision - The new revision for the modified pagesjava.io.IOException - If we have an error while trying to access the pageabstract DeleteResult<K,V> delete(K key, V value, long revision, Page<K,V> parent, int parentPos) throws java.io.IOException
key - The key to deletevalue - The value to deleterevision - The revision for which we want to delete a tupleparent - The parent pageparentPos - The position of this page in the parent pagejava.io.IOException - If we had an issue while processing the deletionpublic V get(K key) throws java.io.IOException, KeyNotFoundException
get in interface Page<K,V>key - The key we are looking forjava.io.IOException - If we have an error while trying to access the pageKeyNotFoundException - If no entry with the given key can be foundvoid setPageHolder(int pos,
PageHolder<K,V> pageHolder)
pos - The position of the added pageHolderpageHolder - The pageHolder to addpublic ValueCursor<V> getValues(K key) throws KeyNotFoundException, java.io.IOException, java.lang.IllegalArgumentException
getValues in interface Page<K,V>key - The key we are looking forKeyNotFoundException - If no entry with the given key can be foundjava.io.IOException - If we have an error while trying to access the pagejava.lang.IllegalArgumentException - If duplicates are not enabledvoid setValue(int pos,
ValueHolder<V> value)
pos - The position in the values arrayvalue - the value to injectpublic TupleCursor<K,V> browse(ReadTransaction<K,V> transaction, ParentPos<K,V>[] stack, int depth) throws java.io.IOException
browse in interface Page<K,V>transaction - The started transaction for this operationstack - The stack of parents we go through to get to this pagejava.io.IOException - If we have an error while trying to access the pagepublic KeyCursor<K> browseKeys(ReadTransaction<K,K> transaction, ParentPos<K,K>[] stack, int depth) throws java.io.IOException
browseKeys in interface Page<K,V>transaction - The started transaction for this operationstack - The stack of parents we go through to get to this pagejava.io.IOException - If we have an error while trying to access the pageprotected int selectSibling(Page<K,V> parent, int parentPos) throws java.io.IOException
parent - The parent of the current pageThe - position of the current page reference in its parentjava.io.IOException - If we have an error while trying to access the pagepublic K getLeftMostKey()
getLeftMostKey in interface Page<K,V>public K getRightMostKey()
getRightMostKey in interface Page<K,V>long getOffset()
PageIO which stores the Page on disk.void setOffset(long offset)
offset - the offset to setlong getLastOffset()
PageIO which stores the Page on disk.void setLastOffset(long lastOffset)
void setKey(int pos,
KeyHolder<K> key)
pos - The position in the keys arraykey - the key to injectValueHolder<V> getValue(int pos)
public long getRevision()
getRevision in interface Page<K,V>void setRevision(long revision)
revision - the revision to setprotected final int compare(K key1, K key2)
key1 - The first keykey2 - The second keypublic int findPos(K key)
+---+---+---+---+ | b | d | f | h | +---+---+---+---+ 0 1 2 3looking for 'b' will return -1 (-(0+1)) and looking for 'f' will return -3 (-(2+1)).
public Tuple<K,V> findLeftMost() throws EndOfFileExceededException, java.io.IOException
findLeftMost in interface Page<K,V>java.io.IOException - If we have an error while trying to access the pageEndOfFileExceededExceptionpublic Tuple<K,V> findRightMost() throws EndOfFileExceededException, java.io.IOException
findRightMost in interface Page<K,V>java.io.IOException - If we have an error while trying to access the pageEndOfFileExceededExceptionpublic java.lang.String dumpPage(java.lang.String tabs)
public java.lang.String toString()
toString in class java.lang.ObjectObject.toString()