Bonsai is a zero-dependency Rust library that intelligently adapts to data changes by switching between spatial index structures like R-trees and KD-trees. It offers seamless performance enhancements through runtime profiling of data and queries, ensuring optimal indexing without developer oversight. Simplifying spatial queries has never been easier.
Bonsai is a versatile, zero-dependency Rust library that delivers a self-tuning spatial index capable of adapting to the dynamic changes in data and query performance requirements. This library operates transparently, continuously profiling the data and query workload at runtime, and seamlessly switching between various index backends — including R-tree, KD-tree, Quadtree, and Grid — to ensure optimal query performance without requiring intervention from developers.
f32 and f64 coordinate types.Bonsai can be easily added to Rust projects as a dependency through Cargo. For more details on installation, refer to the crate page.
To illustrate its capabilities, here are several usage examples:
use bonsai::BonsaiIndex;
use bonsai::types::{BBox, Point};
let mut index = BonsaiIndex::<&str>::builder().build();
index.insert(Point::new([1.0, 2.0]), "alpha");
index.insert(Point::new([3.0, 4.0]), "beta");
index.insert(Point::new([5.0, 6.0]), "gamma");
index.insert(Point::new([7.0, 8.0]), "delta");
index.insert(Point::new([9.0, 0.0]), "epsilon");
let bbox = BBox::new(Point::new([0.0, 0.0]), Point::new([6.0, 6.0]));
let results = index.range_query(&bbox);
println!("range hits: {}", results.len()); // alpha, beta, gamma
// 6D: [x, y, z, roll, pitch, yaw]
let mut index = BonsaiIndex::<String, f64, 6>::builder()
.initial_backend(bonsai::types::BackendKind::KDTree)
.reservoir_size(2048)
.build();
index.insert(Point::new([1.0, 2.0, 3.0, 0.1, 0.2, 0.3]), "pose_a".to_string());
Bonsai provides a range of configuration options that cater to the specific needs and performance goals of different applications. For instance, one can adjust the starting backend, tuning thresholds for migration, and other factors.
Bonsai features an easy-to-use C FFI layer, allowing integration with languages that support C interoperability, such as Python, making it versatile for multi-language projects.
#include <stdio.h>
#include "bonsai.h"
int main(void) {
BonsaiHandle *idx = bonsai_new();
// Perform operations such as insertion and queries
bonsai_free(idx);
return 0;
}
Bonsai is well-suited for various applications, including but not limited to:
Bonsai employs a lock-free architecture designed to minimize query blocking during migrations, ensuring high performance and responsiveness.
In conclusion, Bonsai is an advanced spatial indexing solution enabling efficient data querying and adaptability, catering to diverse application domains.
No comments yet.
Sign in to be the first to comment.