[][src]Struct broccoli::container::TreeRef

#[repr(transparent)]pub struct TreeRef<'a, A: Axis, T: Aabb> { /* fields omitted */ }

Provides a function to allow the user to ger the original slice of elements (sorted by the tree). Derefs to Tree.

With the regular Tree, you can't get access to the underlying list of elements after the tree has been constructed without destroying the tree.

use broccoli::{prelude::*,bbox,rect};
let mut k=[bbox(rect(0,10,0,10),8)];
let mut b=broccoli::new(&mut k);
b.find_colliding_pairs_mut(|a,b|{});
k[0].inner=4;    
// b.find_colliding_pairs_mut(|a,b|{}); //<---can't use tree again

With a regular Tree you can certainly iterate over all elements in the tree by using vistr_mut, but you can't get a slice to the whole continguous list of elements.

TreeRef provides the function TreeRef::get_bbox_elements_mut that allows the user to get mutable access to the underlying slice of elements. The elements are in the order determined during construction of the tree, i.e. its not the same as the original order passed in. The user is also forbidden from mutating the aabbs of each element. Only whats inside of it besides the aabb can be mutated.

There's not really many usecases where the user would need to use this function, though. Especially since you can already iterate over all elements mutably by calling vistr_mut.

 use broccoli::{prelude::*,bbox,rect};
 let mut bots = [bbox(rect(0,10,0,10),0)];
 let mut tree = broccoli::new(&mut bots);

 use compt::Visitor;
 for b in tree.vistr_mut().dfs_preorder_iter().flat_map(|n|n.into_range().iter_mut()){
    *b.unpack_inner()+=1;    
 }
 assert_eq!(bots[0].inner,1);

However it is useful to implement the crate::analyze::assert functions because we can preserve the tree, and at the same time get the underlying slice to perform the naive query algorithm, and still preserve the tree to avoid having to rebuild it.

Implementations

impl<'a, T: Aabb> TreeRef<'a, DefaultA, T>[src]

pub fn new(arr: &'a mut [T]) -> TreeRef<'a, DefaultA, T>[src]

impl<'a, T: Aabb + Send + Sync> TreeRef<'a, DefaultA, T> where
    T::Num: Send + Sync
[src]

pub fn new_par(arr: &'a mut [T]) -> TreeRef<'a, DefaultA, T>[src]

impl<'a, A: Axis, T: Aabb + Send + Sync> TreeRef<'a, A, T> where
    T::Num: Send + Sync
[src]

pub fn with_axis_par(a: A, arr: &'a mut [T]) -> TreeRef<'a, A, T>[src]

impl<'a, A: Axis, T: Aabb> TreeRef<'a, A, T>[src]

pub fn with_axis(a: A, arr: &'a mut [T]) -> TreeRef<'a, A, T>[src]

pub fn get_bbox_elements(&self) -> &[T]

Notable traits for &'_ mut [u8]

impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
[src]

use broccoli::{prelude::*,bbox,rect};
let mut k=[bbox(rect(0,10,0,10),8)];
let mut b=broccoli::container::TreeRef::new(&mut k);
b.find_colliding_pairs_mut(|a,b|{});
assert_eq!(b.get_bbox_elements()[0].inner,8);
b.find_colliding_pairs_mut(|a,b|{});

pub fn get_bbox_elements_mut(&mut self) -> PMut<'a, [T]>[src]

use broccoli::{prelude::*,bbox,rect};
let mut k=[bbox(rect(0,10,0,10),8)];
let mut b=broccoli::container::TreeRef::new(&mut k);
b.find_colliding_pairs_mut(|a,b|{});
*b.get_bbox_elements_mut().get_index_mut(0).unpack_inner()=5;
b.find_colliding_pairs_mut(|a,b|{});

Methods from Deref<Target = Tree<'a, A, T>>

#[must_use]pub fn get_height(&self) -> usize[src]

Examples

 use broccoli::analyze;
 const NUM_ELEMENT:usize=400;
 let mut bots = [axgeom::rect(0,10,0,10);NUM_ELEMENT];
 let mut tree = broccoli::new(&mut bots);

 assert_eq!(tree.get_height(),analyze::TreePreBuilder::new(NUM_ELEMENT).get_height());

#[must_use]pub fn num_nodes(&self) -> usize[src]

Examples

 use broccoli::analyze;
 let mut bots = [axgeom::rect(0,10,0,10)];
 let mut tree = broccoli::new(&mut bots);

 assert_eq!(tree.num_nodes(),analyze::TreePreBuilder::new(1).num_nodes());

#[must_use]pub fn get_nodes(&self) -> &[Node<'a, T>]

Notable traits for &'_ mut [u8]

impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
[src]

Examples

 use broccoli::analyze;
 let mut bots = [axgeom::rect(0,10,0,10)];
 let mut tree = broccoli::new(&mut bots);

 assert_eq!(tree.get_nodes()[0].range[0], axgeom::rect(0,10,0,10));

#[must_use]pub fn get_nodes_mut(&mut self) -> PMut<'_, [Node<'a, T>]>[src]

Examples

 use broccoli::analyze;
 let mut bots = [axgeom::rect(0,10,0,10)];
 let mut tree = broccoli::new(&mut bots);

 assert_eq!(tree.get_nodes_mut().get_index_mut(0).range[0], axgeom::rect(0,10,0,10));

Trait Implementations

impl<'a, A: Axis, T: Aabb> Deref for TreeRef<'a, A, T>[src]

type Target = Tree<'a, A, T>

The resulting type after dereferencing.

impl<'a, A: Axis, T: Aabb> DerefMut for TreeRef<'a, A, T>[src]

Auto Trait Implementations

impl<'a, A, T> RefUnwindSafe for TreeRef<'a, A, T> where
    A: RefUnwindSafe,
    T: RefUnwindSafe,
    <T as Aabb>::Num: RefUnwindSafe
[src]

impl<'a, A, T> Send for TreeRef<'a, A, T> where
    T: Send,
    <T as Aabb>::Num: Send
[src]

impl<'a, A, T> Sync for TreeRef<'a, A, T> where
    T: Sync,
    <T as Aabb>::Num: Sync
[src]

impl<'a, A, T> Unpin for TreeRef<'a, A, T> where
    A: Unpin
[src]

impl<'a, A, T> !UnwindSafe for TreeRef<'a, A, T>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.