A robust, generic B+ tree implementation in Zig. High performance, memory-safe, and designed for both production use and learning.
A self-balancing tree data structure for fast sorted access. All values live in leaf nodes; internal nodes store only keys for navigation. Used in databases and filesystems.
- Generic: Any comparable key/value type
- Self-balancing: O(log n) operations
- Memory-safe: Proper allocator patterns
- Tested: Full test coverage
- MIT licensed: Free for any use
With zig fetch:
zig fetch --save git+https://github.com/dayvster/zig-bplus-treeAdd to build.zig.zon:
"bplustree": { "url": "https://github.com/dayvster/zig-bplus-tree/archive/refs/heads/main.zip" }Then import: const BPlusTree = @import("bplustree").BPlusTree(i32, 4);
Or copy manually: src/bplustree.zig to your project.
var tree = BPlusTree(i32, i32, 4).init(allocator); // MemoryPool strategy (faster)
defer tree.deinit();
try tree.insert(42, 100);
const found = tree.search(42);See examples/ for more patterns and stress tests.
- Build:
zig build - Test:
zig build test - Format:
zig fmt src/
Issues and PRs welcome! Start a discussion or open an issue on GitHub.
MIT. See LICENSE.