Skip to content

Latest commit

 

History

History
36 lines (25 loc) · 1.14 KB

inserting_elements_in_a_batch.md

File metadata and controls

36 lines (25 loc) · 1.14 KB

Inserting Elements In A Batch

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