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
Modifier and TypeFieldDescriptionint[]
-
Constructor Summary
ConstructorDescriptionBPlusInternalNode
(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 TypeMethodDescriptionint
Adds a key and its right child to their correct locations within the node.int
add
(KeyType keyToAdd, long childOffset, BPlusNode<KeyType, KeyBufferType> child) Adds a key and its right child to their correct locations within the node.void
add
(KeyType keyToAdd, long offs, BPlusNode<KeyType, KeyBufferType> child, int indexToInsert) Adds a key and its right child to their correct locations within the node.void
addFirstChild
(BPlusNode<KeyType, KeyBufferType> childToAdd, int len) Adds a child offset to the beginning of the children (leftmost).void
addFirstChildOffset
(long childToAdd, int len) Adds a child offset to the beginning of the children (leftmost).void
addFirstKey
(KeyType keyToAdd) Adds the key to the beginning of the keys.void
Adds a child to the end of the children.void
appendChild
(BPlusNode<KeyType, KeyBufferType> childToAdd) Adds a child to the end of the children.void
appendChildOffset
(long childToAdd) Adds a child offset to the end of the children.void
Adds a key to the end of the keys.Returns a child from the right side.long
Returns a child offset from the right side.long
boolean
checkSanity
(String message, KeyType minKey, KeyType maxKey, DataFile df) checks whether all keys are sorted correctlyvoid
clear()
set the left sibling offsetbyte[]
Map node to an array of bytesvoid
Deletes the key (and the associated record offset) from this node.void
Removes the first child offset and shifts.void
Removes the first child and shifts.void
deleteKey
(int keyIndex, boolean deleteLeft) Deletes the key at the given index.void
Deletes the given key from the index.void
destroy()
free up ressources at the end (CacheManager.clear)void
performs several cleaning up actions after borrowing from the right.void
Removes entries.findSeparatingKey
(long left) Finds the separating key between left and right.getChild
(int index) int[]
int
boolean
isLeaf()
A quick checker to see if the node is a leaf- if so, we have found the final result of the search.void
remove()
void
This method is used when the tree has to delete something: it should have found an immediate predecessor to replace this value.long
This method returns the offset of the child that should contain the key, if it is in the tree.int
searchIndex
(KeyType key) This method returns the index of the child that should contain the key, if it is in the tree.int
void
substitute
(BPlusKeys<KeyType, KeyBufferType> key, int[] offsets, BPlusNode<KeyType, KeyBufferType>[] childs, long left) substitute the data of a bplus nodevoid
Reassigns 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:BPlusNode
A quick checker to see if the node is a leaf- if so, we have found the final result of the search.- Specified by:
isLeaf
in 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:BPlusNode
performs several cleaning up actions after borrowing from the right.- Specified by:
doneBorrowing
in 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:BPlusNode
set the left sibling offset- Overrides:
clear
in 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:
doneBorrowingFirst
in 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:BPlusNode
checks whether all keys are sorted correctly- Specified by:
checkSanity
in classBPlusNode<KeyType,
KeyBufferType> - Returns:
-
remove
public void remove() -
destroy
public void destroy()Description copied from interface:CacheUnit
free up ressources at the end (CacheManager.clear) -
createBytes
public byte[] createBytes()Map node to an array of bytes- Returns:
-