Skip to content

Latest commit

 

History

History
43 lines (31 loc) · 1.12 KB

inserting_one_element_at_a_time.md

File metadata and controls

43 lines (31 loc) · 1.12 KB

Inserting One Element At A Time

To insert an element to the tree, we can use insert.

tree.insert((1, 2));

The complete code is shown below:

use rstar::RTree;

fn main() {
    let mut tree = RTree::new();
    
    tree.insert((0, 0));
    tree.insert((1, 2));
    tree.insert((8, 5));

    for element in &tree {
        println!("{:?}", element);
    }
}

Output:

(8, 5)
(1, 2)
(0, 0)

In the example, the elements in the tree are of type (i32, i32). We can build an RTree to store other types of elements. The acceptable types include tuples with length up to 9 as well as arrays. The tuples and arrays can contain integers and floating-point numbers. In general, an RTree can store elements of type RTreeObject.

➡️ Next: Inserting Elements In A Batch

📘 Back: Table of contents