Package org.grp1.index
Class BPlusTree
java.lang.Object
org.grp1.index.BPlusTree
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final DiskThe disk that contains this BPlus Treeprivate final intThe number of maximum key inside a nodeprivate final InternalNodeSentinel node that helps us to generalize the logic, also known as dummy/ghost node -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintThe function to calculate the number of nodes inside BPlus TreeintThe function to calculate the number of levels of BPlus TreevoiddeleteRecord(int numVotes) The function to delete by numVotesintThe function to get the maximum number of keyprivate intgetNodeFirstKey(Node node) The function that returns the first keygetRecordsByNumVotes(int numVotes) The function that get the record by numVotesgetRecordsByNumVotes(int lowerNumVotes, int higherNumVotes) The function that get the multiple records by the range of numVotesgetRoot()The function to return the root of the treevoidinsertAddress(Address newAddress, int key) The function to insert the record using its addressvoidThe function to display the content of the rootprivate booleanrecursiveDeleteNode(Node node, int numVotes) The function to recursively delete the node by numVotesprivate NoderecursiveInsertNode(Node node, Address newAddress, int key) The function to recursively insert the new record into the BPlus TreebooleantestTree()The function to test the correctness of the tree based on the key value
-
Field Details
-
maxKeyNumber
private final int maxKeyNumberThe number of maximum key inside a node -
disk
The disk that contains this BPlus Tree -
sentinelNode
Sentinel node that helps us to generalize the logic, also known as dummy/ghost node
-
-
Constructor Details
-
BPlusTree
Constructor to instantiate the BPlusTree- Parameters:
maxKeyNumber- The maximum number of keydisk- The disk where this BPlusTree belong
-
-
Method Details
-
testTree
public boolean testTree()The function to test the correctness of the tree based on the key value- Returns:
- Whether the tree is valid or not
-
getNodeFirstKey
The function that returns the first key- Parameters:
node- the node that it wants to get the first key- Returns:
- the first key that belongs to the node
-
getRecordsByNumVotes
The function that get the record by numVotes- Parameters:
numVotes- The associated target numVotes- Returns:
- The list of records that match numVotes
-
getRecordsByNumVotes
The function that get the multiple records by the range of numVotes- Parameters:
lowerNumVotes- The lower bound of targethigherNumVotes- The upper bound of target- Returns:
- The list of Records that fall under the range
-
getRoot
The function to return the root of the tree- Returns:
- The root of the BPlus Tree
-
recursiveDeleteNode
The function to recursively delete the node by numVotes- Parameters:
node- The node of consideration recursivelynumVotes- The target numVotes to delete- Returns:
- Whether one of the children has been deleted
- Throws:
LeafFullException
-
recursiveInsertNode
The function to recursively insert the new record into the BPlus Tree- Parameters:
node- The node of consideration recursivelynewAddress- The address of the record that is to be insertedkey- The key of the record that we want to insert- Returns:
- Null if there is no need to change the node, else return the new node created in the process of insertion
- Throws:
LeafFullException
-
insertAddress
The function to insert the record using its address- Parameters:
newAddress- The address of the new recordkey- The key of the record to be inserted- Throws:
LeafFullException
-
deleteRecord
The function to delete by numVotes- Parameters:
numVotes- The numVotes of the records to be deleted- Throws:
Exception
-
getMaxKeyNumber
public int getMaxKeyNumber()The function to get the maximum number of key- Returns:
-
printRootKeys
public void printRootKeys()The function to display the content of the root -
calculateNumLevels
public int calculateNumLevels()The function to calculate the number of levels of BPlus Tree- Returns:
- The number of levels that BPlus Tree has
-
calculateNodes
public int calculateNodes()The function to calculate the number of nodes inside BPlus Tree- Returns:
- The number of nodes inside BPlus Tree
-