Struct rupta::util::index_tree::IndexTree
source · pub struct IndexTree<T> { /* private fields */ }Expand description
A tree structure implemented using a single Vec and numerical identifiers (indices in the vector) instead of reference counted pointers like.
Implementations§
source§impl<T> IndexTree<T>
impl<T> IndexTree<T>
sourcepub fn get(&self, id: usize) -> Option<&Node<T>>
pub fn get(&self, id: usize) -> Option<&Node<T>>
Returns a reference to the node with the given id if in the tree.
sourcepub fn get_mut(&mut self, id: usize) -> Option<&mut Node<T>>
pub fn get_mut(&mut self, id: usize) -> Option<&mut Node<T>>
Returns a mutable reference to the node with the given id if in the tree.
sourcepub fn add_child(&mut self, parent_id: usize, data: T) -> usize
pub fn add_child(&mut self, parent_id: usize, data: T) -> usize
Appends a new child to the node with parent_id, after existing children.
sourcepub fn children(&self, id: usize) -> Children<'_, T> ⓘ
pub fn children(&self, id: usize) -> Children<'_, T> ⓘ
Returns an iterator of IDs of a given node’s children.
sourcepub fn find_child<F>(&self, parent_id: usize, f: F) -> Option<usize>
pub fn find_child<F>(&self, parent_id: usize, f: F) -> Option<usize>
Finds the child specified by the predicate.
sourcepub fn descendants(&self, id: usize) -> Descendants<'_, T> ⓘ
pub fn descendants(&self, id: usize) -> Descendants<'_, T> ⓘ
An iterator of the IDs of a given node and its descendants, as a pre-order depth-first search where children are visited in insertion order.
Trait Implementations§
Auto Trait Implementations§
impl<T> RefUnwindSafe for IndexTree<T>where
T: RefUnwindSafe,
impl<T> Send for IndexTree<T>where
T: Send,
impl<T> Sync for IndexTree<T>where
T: Sync,
impl<T> Unpin for IndexTree<T>where
T: Unpin,
impl<T> UnwindSafe for IndexTree<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more