Closed ie-Yoshisaur closed 3 months ago
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 95.08%. Comparing base (
65ca19d
) to head (b772765
).
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
By the way: would you like to spend some more time with this class?
Of course! I’ll work on fixing that issue and submit a PR soon.
Description
This pull request optimizes the search function in the BTree implementation by replacing the linear search with a binary search algorithm. This change significantly improves the search performance, especially for large trees, without altering the existing functionality.
The optimization is achieved by modifying the
search
method in theBTree
struct to use thebinary_search
method on thekeys
vector instead of a while loop. This change reduces the time complexity of searching within a node from O(n) to O(log n), where n is the number of keys in the node.Type of change
Implementation Details
The main changes are in the
search
method of theBTree
struct:binary_search
method on thekeys
vector.Benchmark Results
Environment: MacOS 14.5, Apple M1 Pro, 32 GB RAM Dataset: 1,000,000 random integers for insertion, 1,000,000 searches for the key 500,000
Before optimization:
After optimization:
Note: Insertion time remains largely unchanged, as expected.
Checklist:
cargo clippy --all -- -D warnings
just before my last commit and fixed any issue that was found.cargo fmt
just before my last commit.cargo test
just before my last commit and all tests passed.CONTRIBUTING.md
and my code follows its guidelines.All existing tests pass with the new implementation. No new tests were added as the existing ones adequately cover the modified functionality.