Class BPlusInternalNode<KeyType,KeyBufferType>
java.lang.Object
com.semedy.reasoner.edb.persistentstore.bplustree.BPlusNode<KeyType,KeyBufferType>
com.semedy.reasoner.edb.persistentstore.bplustree.BPlusInternalNode<KeyType,KeyBufferType>
- Type Parameters:
KeyType-KeyBufferType-
- All Implemented Interfaces:
CacheUnit
Represents an internal node within the B+ tree. Holds keys and a reference to children.
- Author:
- angele
-
Nested Class Summary
Nested classes/interfaces inherited from class com.semedy.reasoner.edb.persistentstore.bplustree.BPlusNode
BPlusNode.BPlusStatus -
Field Summary
FieldsModifier and TypeFieldDescriptionint[] -
Constructor Summary
ConstructorsConstructorDescriptionBPlusInternalNode(BPlusKeys<KeyType, KeyBufferType> keys, int[] offsets, int maxSizeInBytes, BPlusTree<KeyType, KeyBufferType> bplustree) Constructor: sets instance data.BPlusInternalNode(BPlusKeys<KeyType, KeyBufferType> keys, int[] offsets, BPlusNode<KeyType, KeyBufferType>[] children, int maxSizeInBytes, BPlusTree<KeyType, KeyBufferType> bplustree) A constructor for when the left and right are known. -
Method Summary
Modifier and TypeMethodDescriptionintAdds a key and its right child to their correct locations within the node.intadd(KeyType keyToAdd, long childOffset, BPlusNode<KeyType, KeyBufferType> child) Adds a key and its right child to their correct locations within the node.voidadd(KeyType keyToAdd, long offs, BPlusNode<KeyType, KeyBufferType> child, int indexToInsert) Adds a key and its right child to their correct locations within the node.voidaddFirstChild(BPlusNode<KeyType, KeyBufferType> childToAdd, int len) Adds a child offset to the beginning of the children (leftmost).voidaddFirstChildOffset(long childToAdd, int len) Adds a child offset to the beginning of the children (leftmost).voidaddFirstKey(KeyType keyToAdd) Adds the key to the beginning of the keys.voidAdds a child to the end of the children.voidappendChild(BPlusNode<KeyType, KeyBufferType> childToAdd) Adds a child to the end of the children.voidappendChildOffset(long childToAdd) Adds a child offset to the end of the children.voidAdds a key to the end of the keys.Returns a child from the right side.longReturns a child offset from the right side.longbooleancheckSanity(String message, KeyType minKey, KeyType maxKey, DataFile df) checks whether all keys are sorted correctlyvoidclear()set the left sibling offsetbyte[]Map node to an array of bytesvoidDeletes the key (and the associated record offset) from this node.voidRemoves the first child offset and shifts.voidRemoves the first child and shifts.voiddeleteKey(int keyIndex, boolean deleteLeft) Deletes the key at the given index.voidDeletes the given key from the index.voiddestroy()free up ressources at the end (CacheManager.clear)voidperforms several cleaning up actions after borrowing from the right.voidRemoves entries.findSeparatingKey(long left) Finds the separating key between left and right.getChild(int index) int[]intbooleanisLeaf()A quick checker to see if the node is a leaf- if so, we have found the final result of the search.voidremove()voidThis method is used when the tree has to delete something: it should have found an immediate predecessor to replace this value.longThis method returns the offset of the child that should contain the key, if it is in the tree.intsearchIndex(KeyType key) This method returns the index of the child that should contain the key, if it is in the tree.intvoidsubstitute(BPlusKeys<KeyType, KeyBufferType> key, int[] offsets, BPlusNode<KeyType, KeyBufferType>[] childs, long left) substitute the data of a bplus nodevoidReassigns the key at index with newKey.Methods inherited from class com.semedy.reasoner.edb.persistentstore.bplustree.BPlusNode
borrowFirstKey, borrowKey, canBeBorrowedFrom, detach, getFather, getIndexInFather, getKeys, getLast, getNext, getNumKeys, getOffset, getStatus, isEmpty, isFull, isReleasable, release, setFather, setLast, setNext, setStatus, sizeInBytes, toString, touch, underflow
-
Field Details
-
_childOffsets
public int[] _childOffsets -
_children
-
-
Constructor Details
-
BPlusInternalNode
public BPlusInternalNode(BPlusKeys<KeyType, KeyBufferType> keys, int[] offsets, int maxSizeInBytes, BPlusTree<KeyType, KeyBufferType> bplustree) Constructor: sets instance data.- Parameters:
keys-offsets-maxSizeInBytes-bplustree-
-
BPlusInternalNode
public BPlusInternalNode(BPlusKeys<KeyType, KeyBufferType> keys, int[] offsets, BPlusNode<KeyType, KeyBufferType>[] children, int maxSizeInBytes, BPlusTree<KeyType, KeyBufferType> bplustree) A constructor for when the left and right are known.- Parameters:
keys-offsets-children-maxSizeInBytes-bplustree-
-
-
Method Details
-
getChild
-
substitute
public void substitute(BPlusKeys<KeyType, KeyBufferType> key, int[] offsets, BPlusNode<KeyType, KeyBufferType>[] childs, long left) substitute the data of a bplus node- Parameters:
key-offsets-childs-left-
-
getNumChildren
public int getNumChildren()- Returns:
- number of children contained in this node.
-
getChildOffsets
public int[] getChildOffsets()- Returns:
- an array containing the child offsets of this node
-
getChildren
- Returns:
- an array containing the children of this node
-
replace
This method is used when the tree has to delete something: it should have found an immediate predecessor to replace this value.- Parameters:
keyToReplace-replacement-
-
add
Adds a key and its right child to their correct locations within the node.- Parameters:
keyToAdd-childOffset-- Throws:
IOException
-
add
Adds a key and its right child to their correct locations within the node.- Parameters:
keyToAdd-childOffset- + @PARAM child
-
add
public void add(KeyType keyToAdd, long offs, BPlusNode<KeyType, KeyBufferType> child, int indexToInsert) throws IOExceptionAdds a key and its right child to their correct locations within the node.- Parameters:
keyToAdd-offs- , file offset of left childchild-indexToInsert- index to insert key- Throws:
IOException
-
addFirstKey
Adds the key to the beginning of the keys. Should only be called if you also plan on adding a child.- Parameters:
keyToAdd-- Throws:
IOException
-
addFirstChildOffset
public void addFirstChildOffset(long childToAdd, int len) Adds a child offset to the beginning of the children (leftmost). Should only be called if you plan on adding a key.- Parameters:
childToAdd-
-
addFirstChild
Adds a child offset to the beginning of the children (leftmost). Should only be called if you plan on adding a key.- Parameters:
childToAdd-
-
search
This method returns the offset of the child that should contain the key, if it is in the tree.- Parameters:
key-- Returns:
- the offset where the node that may contain the key is located
-
searchIndex
This method returns the index of the child that should contain the key, if it is in the tree.
Otherwise returns the index where to place the child- Parameters:
key-- Returns:
- the offset where the node that may contain the key is located
-
searchIndexBuffer
-
isLeaf
public boolean isLeaf()Description copied from class:BPlusNodeA quick checker to see if the node is a leaf- if so, we have found the final result of the search.- Specified by:
isLeafin classBPlusNode<KeyType,KeyBufferType> - Returns:
- true if this is a leaf
-
updateKey
Reassigns the key at index with newKey.- Parameters:
index-newKey-
-
deleteKey
public void deleteKey(int keyIndex, boolean deleteLeft) Deletes the key at the given index.- Parameters:
keyIndex-deleteLeft- whether we are trying to delete leftmost child with this key.
-
delete
Deletes the key (and the associated record offset) from this node. First, we find the index of the key. Make a temp array containing keys[0, indexToSkip - 1] copy keys[indexToSkip + 1, keys.length - 1] over. Do the same with the records.- Parameters:
keyToDelete-deleteLeft-
-
deleteKey
Deletes the given key from the index.- Parameters:
keyToDelete-
-
borrowChildOffset
public long borrowChildOffset()Returns a child offset from the right side.- Returns:
- the rightmost child
-
borrowChild
Returns a child from the right side.- Returns:
- the rightmost child
-
doneBorrowing
public void doneBorrowing()Description copied from class:BPlusNodeperforms several cleaning up actions after borrowing from the right.- Specified by:
doneBorrowingin classBPlusNode<KeyType,KeyBufferType>
-
appendKey
Adds a key to the end of the keys.- Parameters:
keyToAdd-- Throws:
IOException
-
appendChildOffset
public void appendChildOffset(long childToAdd) Adds a child offset to the end of the children.- Parameters:
childToAdd-
-
append
Adds a child to the end of the children.- Parameters:
key- , key of childoffs- , file offset- Throws:
IOException
-
clear
public void clear()Description copied from class:BPlusNodeset the left sibling offset- Overrides:
clearin classBPlusNode<KeyType,KeyBufferType>
-
appendChild
Adds a child to the end of the children.- Parameters:
childToAdd-
-
doneBorrowingFirst
public void doneBorrowingFirst()Removes entries. Call only after borrowing from first key AND first child.- Specified by:
doneBorrowingFirstin classBPlusNode<KeyType,KeyBufferType>
-
borrowFirstChildOffset
public long borrowFirstChildOffset()- Returns:
- the first child offset
-
borrowFirstChild
- Returns:
- the first child offset
-
findSeparatingKey
Finds the separating key between left and right.- Parameters:
left-- Returns:
- the key that separates both chidren.
-
deleteFirstChildOffset
public void deleteFirstChildOffset()Removes the first child and shifts. -
deleteFirstChild
public void deleteFirstChild()Removes the first child offset and shifts. -
checkSanity
Description copied from class:BPlusNodechecks whether all keys are sorted correctly- Specified by:
checkSanityin classBPlusNode<KeyType,KeyBufferType> - Returns:
-
remove
public void remove() -
destroy
public void destroy()Description copied from interface:CacheUnitfree up ressources at the end (CacheManager.clear) -
createBytes
public byte[] createBytes()Map node to an array of bytes- Returns:
-