Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: Optimize BTree search using binary search (#767)
* perf: Optimize BTree search using binary search This commit 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. Implementation details: - Modified the `search` method in the `BTree` struct - Replaced the while loop with `binary_search` method on the `keys` vector Complexity analysis: - Previous implementation: O(n) per node, where n is the number of keys - New implementation: O(log n) per node Benchmark results: - Environment: MacOS 14.5, Apple M1 Pro, 32 GB RAM - Dataset: 1,000,000 random integers for insertion - Search: 1,000,000 searches for the key 500,000 - Before: - Insertion: 3.002587333s - Search: 2.334683584s - After: - Insertion: 2.998482583s - Search: 288.659458ms Note: Insertion time remains largely unchanged, as expected. All existing tests pass with the new implementation. Benchmark code is not included in this commit. * tests: expand existing `test_search` --------- Co-authored-by: Piotr Idzik <[email protected]>
- Loading branch information