This project implements a B-tree indexing system in C++ to efficiently manage and manipulate a set of fixed-length records stored in a binary file. The B-tree is used as a secondary index, supporting operations like record insertion, deletion, search, and displaying the structure of the index file.
- B-tree Creation:
- Create a binary file with
nfixed-length records and initialize the B-tree structure.
- Create a binary file with
- Record Insertion:
- Add new records to the B-tree index with support for node splitting when required.
- Record Deletion:
- Remove a record from the index and update the tree structure accordingly.
- Search:
- Search for a record in the B-tree and retrieve its reference from the data file.
- Display:
- Visualize the content of the index file, showing each node on a new line.
-
File Structure:
- Each record consists of:
- m descendants: m Record IDs and m references.
- 1 integer indicating whether the node is a leaf (0) or an internal node (1).
- Node 0 always stores metadata:
- The index of the first empty node at its second integer position.
- Serves as a linked list of empty nodes.
- Each record consists of:
-
Node Indexing:
- The root node is always initialized at index 1.
- Empty nodes form a linked list for efficient allocation during insertion.
The program is implemented using the following key functions:
- Initializes the binary file with
numberOfRecordsand configures the B-tree structure. - Each empty node points to the next empty node, forming a linked list.
- Inserts a new record into the B-tree.
- Returns:
-1if there is no space to insert.- The index of the node where the record is inserted if successful.
- Deletes a record from the B-tree and updates the index structure.
- Displays the content of the index file, showing each node on a new line.
- Searches for a record in the B-tree.
- Returns:
-1if the record does not exist.- The reference to the data file if the record is found.