Our project utilizes three types of trees: Red-Black Tree, AVL Tree, and B-Tree. These trees are employed for file indexing and replicate the functionality of a Database Management System (DBMS).
This class defines the data structure used in our B-Tree. Each object of this class stores one line read from the CSV files. The data is set using a constructor.
The BTree class contains the root node. To initiate the project, an object of this class is created in the menu function. All the functions, such as traverse, are called on this object. This class also includes functions to operate on the root node.
The Node class contains arrays of DataSet objects and an array that points to the child pointers of the Node's object. It also includes functions to operate on each individual node.
The project operates by calling a menu function in Main. The menu function displays a prompt to input the degree of the B-Tree and presents a menu of options to choose from:
-
Read the File and Construct the B-Tree:
- This option constructs a B-Tree with the details read from the given CSV file. It creates files in the subfolder /Node/ with .txt as the name. This operation calls the insert(DataSet) function on the BTree object.
-
Do a Point Search:
- This option prints out tuples for a given index. If multiple entries exist with the same ID, it displays multiple tuples. This operation calls the traversePoint() function on the BTree object.
-
Specify an Index Range to Search:
- This option prints all the tuples within a given range of ID. This operation calls the traversePoint() function on the BTree object.
-
Delete a Tuple:
- This option deletes the tuple from the B-Tree and also deletes the file corresponding to the tuple in the Nodes subfolder.
-
Edit a Tuple:
- This option provides further options to edit and update the file that was created before.
-
Display the Whole Database:
- This option displays the entire database using the print() function on the BTree object.
-
Exit:
- This function exits the program and releases the dynamically allocated memory.
The Red-Black Tree implementation in this project consists of the following components:
-
RbNode Class:
- Contains the implementation for a single Red-Black Tree node.
-
RbTree Class:
- Contains the implementation for the Red-Black Tree class with functionalities such as insertion, retrieval, color checking, and rotations.
-
FileReaderRB():
- Reads the given CSV files and constructs a Red-Black Tree for the specified key.
-
RBMenu():
- Displays different options for indexing on the Red-Black Tree.
-
saveRBinFile():
- Saves the constructed Red-Black index tree in a text file. The file contains the node data (key, line number, file name).
-
LoadRBfromFile():
- Loads the Red-Black Tree from the created index file, which contains information about the Red-Black Tree nodes.
-
PointSearch():
- Prints the data for a given key by receiving the file name and line number as arguments.
The AVL Tree implementation in this project consists of the following components:
-
AVLNode Class:
- Nodes for AVL Trees. Each node holds the necessary data and has constructors to initialize the node. There is also a destructor to deallocate memory.
-
AVLTree Class:
- Represents the AVL Tree and contains the root node. It provides functions for basic tree operations.
-
AVLLoad():
- Loads the tree from a file.
-
AVLFileReader():
- Reads the specified files, performs indexing, and stores the information about each index in the tree. It then stores the tree in a file.
-
AVLMenu():
- Displays a menu for AVL indexing of the data. Other functions, such as AVLID, AVL113, and AVLCause, call the file reader function to construct the tree according to the specified index option.
To proceed with the program, it is necessary to first read the files and construct the B-Tree. During the construction of the B-Tree, for each line in all files (10 files), the node details are also stored in a file in a subfolder /Nodes/
.
Ensure that a file named ------.csv
is present in the folder where the program is being run.
This project is licensed under the MIT License.