K - The type for the KeyV - The type for the stored valueclass InMemoryLeaf<K,V> extends AbstractPage<K,V>
| Modifier and Type | Field and Description |
|---|---|
protected ValueHolder<V>[] |
values
Values associated with keys
|
btree, children, keys, lastOffset, nbElems, offset, revision| Constructor and Description |
|---|
InMemoryLeaf(BTree<K,V> btree)
Constructor used to create a new Leaf when we read it from a file.
|
InMemoryLeaf(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 |
|---|---|
private InsertResult<K,V> |
addAndSplit(long revision,
K key,
V value,
int pos)
Split a full page into two new pages, a left, a right and a pivot element.
|
private Page<K,V> |
addElement(long revision,
K key,
V value,
int pos)
Adds a new
|
private DeleteResult<K,V> |
borrowFromLeft(Tuple<K,V> removedElement,
long revision,
InMemoryLeaf<K,V> sibling,
int pos)
Borrows an element from the left sibling, creating a new sibling with one
less element and creating a new page where the element to remove has been
deleted and the borrowed element added on the left.
|
private DeleteResult<K,V> |
borrowFromRight(Tuple<K,V> removedElement,
long revision,
InMemoryLeaf<K,V> sibling,
int pos)
Borrows an element from the right sibling, creating a new sibling with one
less element and creating a new page where the element to remove has been
deleted and the borrowed element added on the right.
|
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.
|
boolean |
contains(K key,
V value)
Checks if the page contains the given key with the given value.
|
private Page<K,V> |
copy(long revision,
int nbElems)
Copy the current page and all of the keys, values and children, if it's not a leaf.
|
private void |
copyAfterRemovingElement(boolean keyRemoved,
InMemoryLeaf<K,V> newLeaf,
int pos)
Copies the elements of the current page to a new page
|
(package private) 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.
|
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.
|
(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.
|
InsertResult<K,V> |
insert(K key,
V value,
long revision) |
boolean |
isLeaf() |
boolean |
isNode() |
private DeleteResult<K,V> |
mergeWithSibling(Tuple<K,V> removedElement,
long revision,
InMemoryLeaf<K,V> sibling,
boolean isLeft,
int pos)
Merges the sibling with the current leaf, after having removed the element in the page.
|
private InsertResult<K,V> |
replaceElement(long revision,
K key,
V value,
int pos)
Copy the current page if needed, and replace the value at the position we have found the key.
|
(package private) void |
setValue(int pos,
ValueHolder<V> value)
Sets the value at a give position
|
java.lang.String |
toString() |
compare, delete, findPos, getBtree, getKey, getKeys, getLastOffset, getLeftMostKey, getNbElems, getOffset, getPage, getReference, getRevision, getRightMostKey, selectSibling, setKey, setKeys, setLastOffset, setNbElems, setOffset, setPageHolder, setRevisionprotected ValueHolder<V>[] values
InMemoryLeaf(BTree<K,V> btree)
btree - The BTree this page belongs to.InMemoryLeaf(BTree<K,V> btree, long revision, int nbElems)
btree - The BTree this page belongs to.revision - The page revisionnbElems - The number of elements this page will containpublic InsertResult<K,V> insert(K key, V value, long revision) throws java.io.IOException
java.io.IOExceptionDeleteResult<K,V> delete(K key, V value, long revision, Page<K,V> parent, int parentPos) throws java.io.IOException
delete in class AbstractPage<K,V>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 deletionprivate DeleteResult<K,V> mergeWithSibling(Tuple<K,V> removedElement, long revision, InMemoryLeaf<K,V> sibling, boolean isLeft, int pos) throws EndOfFileExceededException, java.io.IOException
revision - The new revisionsibling - The sibling we will merge withisLeft - Tells if the sibling is on the left or on the rightpos - The position of the removed elementjava.io.IOException - If we have an error while trying to access the pageEndOfFileExceededExceptionprivate DeleteResult<K,V> borrowFromLeft(Tuple<K,V> removedElement, long revision, InMemoryLeaf<K,V> sibling, int pos) throws java.io.IOException
revision - The new revision for all the pagessibling - The left siblingpos - The position of the element to removejava.io.IOException - If we have an error while trying to access the pageprivate DeleteResult<K,V> borrowFromRight(Tuple<K,V> removedElement, long revision, InMemoryLeaf<K,V> sibling, int pos) throws java.io.IOException
revision - The new revision for all the pagessibling - The right siblingpos - The position of the element to removejava.io.IOException - If we have an error while trying to access the pageprivate void copyAfterRemovingElement(boolean keyRemoved,
InMemoryLeaf<K,V> newLeaf,
int pos)
throws java.io.IOException
keyRemoved - a flag stating if the key was removednewLeaf - The new page into which the remaining keys and values will be copiedpos - The position into the page of the element to removejava.io.IOException - If we have an error while trying to access the pagepublic V get(K key) throws KeyNotFoundException, java.io.IOException
get in interface Page<K,V>get in class AbstractPage<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 pagepublic ValueCursor<V> getValues(K key) throws KeyNotFoundException, java.io.IOException, java.lang.IllegalArgumentException
getValues in interface Page<K,V>getValues in class AbstractPage<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 enabledpublic boolean hasKey(K key)
public boolean contains(K key, V value) throws java.io.IOException
AbstractPageValueHolder<V> getValue(int pos)
getValue in class AbstractPage<K,V>void setValue(int pos,
ValueHolder<V> value)
setValue in class AbstractPage<K,V>pos - The position in the values arrayvalue - the value to injectpublic TupleCursor<K,V> browse(K key, ReadTransaction<K,V> transaction, ParentPos<K,V>[] stack, int depth)
browse in interface Page<K,V>browse in class AbstractPage<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 pagepublic TupleCursor<K,V> browse(ReadTransaction<K,V> transaction, ParentPos<K,V>[] stack, int depth)
public KeyCursor<K> browseKeys(ReadTransaction<K,K> transaction, ParentPos<K,K>[] stack, int depth)
browseKeys in interface Page<K,V>browseKeys in class AbstractPage<K,V>transaction - The started transaction for this operationstack - The stack of parents we go through to get to this pageprivate Page<K,V> copy(long revision, int nbElems)
revision - The new revisionnbElems - The number of elements to copyprivate InsertResult<K,V> replaceElement(long revision, K key, V value, int pos) throws java.io.IOException
revision - The new page revisionkey - The new keyvalue - the new valuepos - The position of the key in the pagejava.io.IOException - If we have an error while trying to access the pageprivate Page<K,V> addElement(long revision, K key, V value, int pos)
revision - The revision of the modified pagekey - The key to insertvalue - The value to insertpos - The position into the pageprivate InsertResult<K,V> addAndSplit(long revision, K key, V value, int pos)
revision - The new revision for all the created pageskey - The key to addvalue - The value to addpos - The position of the insertion of the new elementpublic Tuple<K,V> findLeftMost() throws java.io.IOException
findLeftMost in interface Page<K,V>findLeftMost in class AbstractPage<K,V>java.io.IOException - If we have an error while trying to access the pagepublic Tuple<K,V> findRightMost() throws EndOfFileExceededException, java.io.IOException
findRightMost in interface Page<K,V>findRightMost in class AbstractPage<K,V>java.io.IOException - If we have an error while trying to access the pageEndOfFileExceededExceptionpublic boolean isLeaf()
public boolean isNode()
public java.lang.String toString()
toString in class AbstractPage<K,V>Object.toString()