RTreed

Struct RTreed 

Source
pub struct RTreed<K, V: RTreeObject, C> { /* private fields */ }

Implementations§

Source§

impl<K, V: RTreeObject, C> RTreed<K, V, C>

Source

pub fn new(collection: C) -> Self

Examples found in repository?
examples/basic_usage.rs (lines 15-17)
10fn main() {
11    // A hashmap of 2D rectangles will be the underlying collection.
12    let rect_hashmap: HashMap<i32, Rectangle<(i32, i32)>> = HashMap::new();
13
14    // Wrap `RTreed` around the hashmap.
15    let mut rtreed = RTreed::<i32, Rectangle<(i32, i32)>, HashMap<i32, Rectangle<(i32, i32)>>>::new(
16        rect_hashmap,
17    );
18
19    // Insert two rectangles, recording them in the R-tree.
20    rtreed.insert(1, Rectangle::from_corners((0, 0), (1, 1)));
21    rtreed.insert(2, Rectangle::from_corners((1, 1), (2, 2)));
22
23    // Locate the two rectangles in the R-tree.
24    assert_eq!(
25        rtreed
26            .rtree()
27            .locate_in_envelope(&AABB::from_corners((0, 0), (2, 2)))
28            .count(),
29        2
30    );
31
32    // Now remove one of the rectangles, recording this in the R-tree.
33    rtreed.remove(&1);
34
35    // Make the same query to the R-tree as before.
36    // Only one rectangle is now present.
37    assert_eq!(
38        rtreed
39            .rtree()
40            .locate_in_envelope(&AABB::from_corners((0, 0), (2, 2)))
41            .count(),
42        1
43    );
44}
Source§

impl<K, V: RTreeObject, C> RTreed<K, V, C>

Source

pub fn collection(&self) -> &C

Source

pub fn rtree(&self) -> &RTree<GeomWithData<V, K>>

Examples found in repository?
examples/basic_usage.rs (line 26)
10fn main() {
11    // A hashmap of 2D rectangles will be the underlying collection.
12    let rect_hashmap: HashMap<i32, Rectangle<(i32, i32)>> = HashMap::new();
13
14    // Wrap `RTreed` around the hashmap.
15    let mut rtreed = RTreed::<i32, Rectangle<(i32, i32)>, HashMap<i32, Rectangle<(i32, i32)>>>::new(
16        rect_hashmap,
17    );
18
19    // Insert two rectangles, recording them in the R-tree.
20    rtreed.insert(1, Rectangle::from_corners((0, 0), (1, 1)));
21    rtreed.insert(2, Rectangle::from_corners((1, 1), (2, 2)));
22
23    // Locate the two rectangles in the R-tree.
24    assert_eq!(
25        rtreed
26            .rtree()
27            .locate_in_envelope(&AABB::from_corners((0, 0), (2, 2)))
28            .count(),
29        2
30    );
31
32    // Now remove one of the rectangles, recording this in the R-tree.
33    rtreed.remove(&1);
34
35    // Make the same query to the R-tree as before.
36    // Only one rectangle is now present.
37    assert_eq!(
38        rtreed
39            .rtree()
40            .locate_in_envelope(&AABB::from_corners((0, 0), (2, 2)))
41            .count(),
42        1
43    );
44}

Trait Implementations§

Source§

impl<K: Clone, V: Clone + RTreeObject, C: Clone> Clone for RTreed<K, V, C>

Source§

fn clone(&self) -> RTreed<K, V, C>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K: Debug, V: Debug + RTreeObject, C: Debug> Debug for RTreed<K, V, C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K, V: RTreeObject, C: Default> Default for RTreed<K, V, C>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<K, V: RTreeObject, C: Get<K, Item = V>> Get<K> for RTreed<K, V, C>

Source§

fn get(&self, key: &K) -> Option<&V>

Returns a reference to the value corresponding to the key.
Source§

impl<K: Clone, V: Clone + RTreeObject, C: Get<K, Item = V> + Insert<K>> Insert<K> for RTreed<K, V, C>

Source§

fn insert(&mut self, key: K, value: V)

Insert a key-value pair into the collection.
Source§

impl<K, V: RTreeObject, C: IntoIter<K, Item = V>> IntoIter<K> for RTreed<K, V, C>

Source§

type IntoIter = <C as IntoIter<K>>::IntoIter

Iterator that consumes the collection.
Source§

fn into_iter(self) -> C::IntoIter

Consume the collection and yield owned key-value pairs.
Source§

impl<K, V: RTreeObject, C> Keyed for RTreed<K, V, C>

Source§

type Key = K

Source§

impl<K, V: RTreeObject, C> Map for RTreed<K, V, C>

Source§

type Item = V

Source§

impl<K: Clone, V: Clone + RTreeObject, C: Push<K, Item = V>> Push<K> for RTreed<K, V, C>

Source§

fn push(&mut self, value: V) -> K

Insert a value into the collection without specifying a key, returning the key that was automatically generated.
Source§

impl<K: Clone + PartialEq, V: Clone + PartialEq + RTreeObject, C: Remove<K, Item = V>> Remove<K> for RTreed<K, V, C>

Source§

fn remove(&mut self, key: &K) -> Option<V>

Remove a key from the collection, returning the value at the key if the key was previously in the map.

Auto Trait Implementations§

§

impl<K, V, C> Freeze for RTreed<K, V, C>
where C: Freeze, <V as RTreeObject>::Envelope: Freeze,

§

impl<K, V, C> RefUnwindSafe for RTreed<K, V, C>

§

impl<K, V, C> Send for RTreed<K, V, C>
where C: Send, <V as RTreeObject>::Envelope: Send, V: Send, K: Send,

§

impl<K, V, C> Sync for RTreed<K, V, C>
where C: Sync, <V as RTreeObject>::Envelope: Sync, V: Sync, K: Sync,

§

impl<K, V, C> Unpin for RTreed<K, V, C>
where C: Unpin, <V as RTreeObject>::Envelope: Unpin, V: Unpin, K: Unpin,

§

impl<K, V, C> UnwindSafe for RTreed<K, V, C>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.