A simplified B+ tree index implementation designed to run within the Minibase framework.
This project provides:
- Insert (full, with page splits)
- Naïve delete (removes entries without merging or redistribution)
- Range scans (via a
BTFileScanclass) - Basic pin/unpin buffer management calls
- Overview
- Project Structure
- Requirements
- Build & Run Instructions
- Usage
- Testing
- Key Implementation Points
- License
This repository contains a B+ Tree implementation for educational purposes, based on a Minibase‐style database architecture. Operations include:
insert(KeyClass key, RID rid)Delete(KeyClass key, RID rid)(naïve delete)new_scan(KeyClass lo_key, KeyClass hi_key)for range scans
Additionally, you can create a fresh B+ tree, destroy it, and handle pages via Minibase’s buffer manager.
-
Compile
- Navigate into
src/btree(orsrc/tests) and run:make
- Ensure your Makefile’s
CLASSPATHreferences the correct path tobtreelib.jarand yoursrc/folder.
- Navigate into
-
Run Tests
- In
src/tests:make make bttest
- This should launch a sample driver (
BTTest) with a menu to insert records, delete records, and print the B+‐Tree.
- In
-
Direct Java Invocation
- Alternatively:
javac -cp .:../lib/btreelib.jar:../ btree/*.java tests/*.java java -cp .:../lib/btreelib.jar tests.BTTest
- Adjust paths as needed.
- Alternatively:
When running BTTest (or another test driver):
-
Insert a Record
- Provide an integer key when prompted.
- Internally calls
BTreeFile.insert(key, rid).
-
Delete a Record (Naïve Delete)
- Provide the integer key.
- Internally calls
BTreeFile.Delete(key, rid)to remove the matching entry in the leaf.
-
Print All Leaf Pages
- Displays the contents (keys + data RIDs) of each leaf page in sorted order.
-
Print the B+‐Tree Structure
- Shows a higher‐level view of the index pages and leaf pages.
-
Basic Insert
- Insert a few keys (e.g., 10, 20, 30).
- Print the tree.
- All should appear in one leaf if capacity allows.
-
Leaf Splits
- Insert enough keys to overflow a leaf.
- Confirm you see two leaves and a new index root.
-
Index Splits
- Insert more keys (e.g., 1..30) to observe multi‐level splits.
- You should see more than one index page once capacity is exceeded.
-
Duplicates
- Insert multiple identical keys (e.g., 10, 10, 10).
- All appear as separate entries in the leaf.
-
Naïve Delete
- Delete a few keys.
- Confirm they disappear without any merging/redistribution in the leaves.
- Pin/Unpin: Each page is pinned (
pinPage) before reading/modifying and unpinned (unpinPage) after. - Leaf vs. Index Splits:
- Leaf splits return the first key of the new leaf as the
splitKey. - Index splits return the middle key as the new
upEntry.
- Leaf splits return the first key of the new leaf as the
- Naïve Delete:
- Removes
<key, rid>from the leaf. - No merging or redistribution when underfilled.
- Removes
- Duplicates:
- Insert them as separate
<key, rid>entries, sorted by key order.
- Insert them as separate