You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix B+ Tree implementation and tests to address node splitting, key promotion, and key-based access
- **Adjusted `BPlusTreeInternalNode::insert()` Method:**
- Corrected the insertion logic to maintain proper alignment between `keys` and `children` arrays.
- Ensured that when a child node splits, the promoted key is inserted into the current node's `keys`, and the new child node is correctly placed in the `children` array.
- **Modified `split()` Methods in Nodes:**
- Updated `BPlusTreeInternalNode::split()` to correctly calculate the middle index and properly split `keys` and `children` arrays.
- Promoted the appropriate key to the parent node during splits.
- Ensured that each internal node maintains the B+ Tree properties after splitting.
- Adjusted `BPlusTreeLeafNode::split()` to handle small orders and maintain the linked list of leaf nodes.
- **Updated Tree Size Management:**
- Incremented the `size` property in the `BPlusTree` class during insertions to accurately reflect the number of elements.
- Fixed issues where the `size` was not updated, causing `OutOfRangeException` errors.
- **Revised `set` and `get` Methods:**
- Changed `set` and `get` methods to operate on keys rather than indices, aligning with the key-based nature of B+ Trees.
- Updated `set` to traverse the tree and update the value associated with a given key.
- Modified `get` to retrieve the value based on the key, throwing an exception if the key is not found.
- **Fixed Test Cases:**
- Adjusted `testVisualTreeStructure` to insert enough keys to cause node splitting, ensuring both internal and leaf nodes are present.
- Updated `testGetOrder` by correcting the `order` property assignment in the `BPlusTree` class, matching expected values in tests.
- Renamed and modified `testSetAndGetByIndex` to `testSetAndGetByKey`, reflecting the changes in method functionality.
- **Improved Code Consistency and Documentation:**
- Removed redundant property declarations and assignments in the `BPlusTree` constructor.
- Ensured consistent use of the `order` property throughout the class.
- Added comments and documentation to clarify method purposes and enhance readability.
- Ensured alignment between method implementations and their intended use cases.
**Summary:**
These corrections address critical issues in the B+ Tree implementation related to node splitting, key promotion, and data access by keys. By refining the logic in node insertion and splitting methods, the tree now correctly maintains its balanced structure and properties, even with small orders. The `size` property accurately tracks the number of elements, preventing out-of-range errors. The `set` and `get` methods now intuitively operate on keys, improving usability. Tests have been updated to reflect these changes, ensuring the reliability and correctness of the implementation.
0 commit comments