High-performance B+ tree implementations for Rust and Python, designed for efficient range queries and sequential access patterns.
This project provides complete, optimized B+ tree implementations in both languages:
- 🦀 Rust Implementation - Zero-cost abstractions, arena-based memory management
- 🐍 Python Implementation - Competitive with SortedDict, optimized for specific use cases
- Up to 41% faster deletions with optimized rebalancing
- 19-30% improvement in mixed workloads
- Full Rust range syntax support (
3..7
,3..=7
,5..
, etc.)
- Up to 2.5x faster than SortedDict for partial range scans
- 1.4x faster for medium range queries
- Excellent scaling for large dataset iteration
Use Case | Rust | Python |
---|---|---|
Systems programming | ✅ Primary choice | ❌ |
High-performance applications | ✅ Zero-cost abstractions | |
Database engines | ✅ Full control | |
Data analytics | ✅ Fast | ✅ Great for range queries |
Rapid prototyping | ✅ Easy integration | |
Existing Python codebase | ❌ | ✅ Drop-in replacement |
use bplustree::BPlusTreeMap;
let mut tree = BPlusTreeMap::new(16).unwrap();
tree.insert(1, "one");
tree.insert(2, "two");
// Range queries with Rust syntax!
for (key, value) in tree.range(1..=2) {
println!("{}: {}", key, value);
}
from bplustree import BPlusTree
tree = BPlusTree(capacity=128)
tree[1] = "one"
tree[2] = "two"
# Range queries
for key, value in tree.range(1, 2):
print(f"{key}: {value}")
- 📚 Technical Documentation - Architecture, algorithms, benchmarks
- 🦀 Rust Documentation - Rust-specific usage and examples
- 🐍 Python Documentation - Python-specific usage and examples
Comprehensive benchmarking shows significant advantages in specific scenarios:
- Range queries: O(log n + k) complexity with excellent cache locality
- Sequential scans: Linked leaf nodes enable efficient iteration
- Deletion-heavy workloads: Optimized rebalancing algorithms
- Large datasets: Performance improves with scale
- Rust: 19-41% faster deletions, excellent overall performance
- Python: 2.5x faster partial scans, competitive with highly optimized libraries
See performance documentation for detailed analysis and charts.
Both implementations share core design principles:
- Arena-based memory management for efficiency
- Linked leaf nodes for fast sequential access
- Hybrid navigation combining tree traversal + linked list iteration
- Optimized rebalancing with reduced duplicate lookups
- Comprehensive testing including adversarial test patterns
cd rust/
cargo test --features testing
cargo bench
cd python/
pip install -e .
python -m pytest tests/
python scripts/analyze_benchmarks.py
This project follows Test-Driven Development and Tidy First principles:
- Write tests first - All features start with failing tests
- Small, focused commits - Separate structural and behavioral changes
- Comprehensive validation - Both implementations tested against reference implementations
- Performance awareness - All changes benchmarked for performance impact
This project is licensed under the MIT License - see the LICENSE file for details.
- GitHub Repository
- Rust Crate (coming soon)
- Python Package (coming soon)
Built with ❤️ following Kent Beck's Test-Driven Development methodology.