dayvster/zig-bplus-tree
A robust, generic, and idiomatic B+ tree implementation in Zig (0.15+). This package is designed for high performance, reliability, and ease of use—pe...
A robust, generic, and idiomatic B+ tree implementation in Zig (0.15+). This package is designed for high performance, reliability, and ease of use—perfect for use as a dependency or as a learning resource for advanced data structures in Zig.
A B+ tree is a self-balancing tree data structure that maintains sorted data and allows fast insertions, deletions, and lookups. It is widely used in databases and filesystems.
Example (order 4):
[ 10 | 20 ]
/ | \
[1 5 7] [12 15] [22 25 30]
zig fetch
(recommended)Fetch and add this repo as a dependency:
zig fetch --save git+https://github.com/dayvster/zig-bplus-tree
Add to your build.zig.zon
dependencies:
{
"dependencies": {
"bplustree": {
"url": "https://github.com/dayvster/zig-bplus-tree/archive/refs/heads/main.zip"
}
}
}
Then in your build.zig
:
const bplustree_mod = b.dependency("bplustree", .{}).module("bplustree");
// ...
.imports = &.{ .{ .name = "bplustree", .module = bplustree_mod } },
And in your code:
const BPlusTree = @import("bplustree").BPlusTree(i32, 4);
src/bplustree.zig
into your project (e.g. lib/bplustree.zig
).const BPlusTree = @import("lib/bplustree.zig").BPlusTree(i32, 4);
const std = @import("std");
const BPlusTree = @import("bplustree").BPlusTree(i32, 4);
pub fn main() !void {
var tree = BPlusTree.init(&std.heap.page_allocator);
defer tree.deinit();
try tree.insert(42, 100);
const found = tree.search(42);
std.debug.print("Found: {any}\n", .{found});
}
See the examples/
directory for more usage patterns, including:
Run all tests:
zig build test
Pull requests, bug reports, and feature requests are welcome! Please open an issue or PR on GitHub.
If you have questions or need help, open an issue or start a discussion on the repo.
MIT. See LICENSE.