pub struct Navigator { /* private fields */ }
Expand description
The navigator stores the structure of the tree. It knows which nodes are neighbors, parents and children of a node and allows navigating to them. With “navigation” we mean that the index in the flat Vector storing all the nodes is returned.
§Example:
use flange_flat_tree::navigator::Builder;
// A navigator just stores neigbors, so we provide no values
let mut b = Builder::default();
let root = b.start_element();
let child1 = b.start_end_element();
let child2 = b.start_end_element();
let nav = b.build();
assert_eq!(nav.children(root), [child1,child2]);
assert_eq!(nav.next_sibling(child1), Some(child2));
assert_eq!(nav.prev_sibling(child2), Some(child1));
Implementations§
Sourcepub fn for_each_depth_first<F>(&self, f: F)
pub fn for_each_depth_first<F>(&self, f: F)
Iterates through all nodes in a depth-first order. That means the children of a node are garuanteed to be visited before the node itself.
§Example
use flange_flat_tree::navigator::Builder;
// A navigator just stores neigbors, so we provide no values
let mut b = Builder::default();
let root = b.start_element();
let child1 = b.start_end_element();
let child2 = b.start_end_element();
// ...
let nav = b.build();
let mut visited = vec![false;3];
nav.for_each_depth_first(|i, childs| {
visited[i] = true;
for c in childs {
assert!(visited[c]);
}
});
Sourcepub fn get_neighbors(&self, index: usize) -> &Neighbors<usize>
pub fn get_neighbors(&self, index: usize) -> &Neighbors<usize>
Sourcepub fn first_child(&self, index: usize) -> Option<usize>
pub fn first_child(&self, index: usize) -> Option<usize>
Sourcepub fn prev_sibling(&self, index: usize) -> Option<usize>
pub fn prev_sibling(&self, index: usize) -> Option<usize>
Sourcepub fn next_sibling(&self, index: usize) -> Option<usize>
pub fn next_sibling(&self, index: usize) -> Option<usize>
Trait Implementations§
Auto Trait Implementations§
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