To insert many elements at a time, we can use bulk_load, which performs more efficiently than executing multiple insert.
let tree = RTree::bulk_load(vec![(0, 0), (1, 2), (8, 5)]);
Note that bulk_load constructs an RTree directly. If we need to insert elements later, we can still use insert on the tree obtained from bulk_load.
The complete code is shown below:
use rstar::RTree;
fn main() {
let tree = RTree::bulk_load(vec![(0, 0), (1, 2), (8, 5)]);
for element in &tree {
println!("{:?}", element);
}
}
Output:
(8, 5)
(1, 2)
(0, 0)
➡️ Next: Existence Queries
📘 Back: Table of contents