Struct flat_tree::Iterator [−][src]
Iterator over a flat-tree.
Methods
impl Iterator
[src]
[−]
impl Iterator
pub fn new(index: usize) -> Self
[src]
[−]
pub fn new(index: usize) -> Self
Create a new iterator.
Examples
use flat_tree::Iterator; assert_eq!(Iterator::new(0).take(3).collect::<Vec<usize>>(), [2, 4, 6]);
pub fn index(&self) -> usize
[src]
[−]
pub fn index(&self) -> usize
Get the current index.
pub fn offset(&self) -> usize
[src]
[−]
pub fn offset(&self) -> usize
Get the current offset.
pub fn seek(&mut self, index: usize)
[src]
[−]
pub fn seek(&mut self, index: usize)
Seek to a position in the iterator.
Examples
let mut iter = flat_tree::Iterator::new(0); iter.seek(4); assert_eq!(iter.next(), Some(6)); iter.seek(2); assert_eq!(iter.next(), Some(4));
pub fn is_left(&self) -> bool
[src]
[−]
pub fn is_left(&self) -> bool
Check if the position of the iterator is currently on a left node.
Examples
assert_eq!(flat_tree::Iterator::new(0).is_left(), true); assert_eq!(flat_tree::Iterator::new(2).is_left(), false); assert_eq!(flat_tree::Iterator::new(1).is_left(), true);
pub fn is_right(&self) -> bool
[src]
[−]
pub fn is_right(&self) -> bool
Check if the position of the iterator is currently on a right node.
Examples
assert_eq!(flat_tree::Iterator::new(0).is_right(), false); assert_eq!(flat_tree::Iterator::new(2).is_right(), true); assert_eq!(flat_tree::Iterator::new(1).is_right(), false);
pub fn prev(&mut self) -> usize
[src]
[−]
pub fn prev(&mut self) -> usize
Move the cursor and get the previous item from the current position.
Examples
let mut iter = flat_tree::Iterator::new(6); assert_eq!(iter.prev(), 4); assert_eq!(iter.prev(), 2); assert_eq!(iter.prev(), 0);
pub fn sibling(&mut self) -> usize
[src]
[−]
pub fn sibling(&mut self) -> usize
Get the sibling for the current position and move the cursor.
Examples
assert_eq!(flat_tree::Iterator::new(0).sibling(), 2); assert_eq!(flat_tree::Iterator::new(1).sibling(), 5); assert_eq!(flat_tree::Iterator::new(4).sibling(), 6);
pub fn parent(&mut self) -> usize
[src]
[−]
pub fn parent(&mut self) -> usize
Get the parent for the current position and move the cursor.
Examples
assert_eq!(flat_tree::Iterator::new(0).parent(), 1); assert_eq!(flat_tree::Iterator::new(1).parent(), 3); assert_eq!(flat_tree::Iterator::new(4).parent(), 5);
pub fn left_span(&mut self) -> usize
[src]
[−]
pub fn left_span(&mut self) -> usize
Get the left_span for the current position and move the cursor.
Examples
assert_eq!(flat_tree::Iterator::new(0).left_span(), 0); assert_eq!(flat_tree::Iterator::new(1).left_span(), 0); assert_eq!(flat_tree::Iterator::new(3).left_span(), 0); assert_eq!(flat_tree::Iterator::new(23).left_span(), 16); assert_eq!(flat_tree::Iterator::new(27).left_span(), 24);
pub fn right_span(&mut self) -> usize
[src]
[−]
pub fn right_span(&mut self) -> usize
Get the right_span for the current position and move the cursor.
Examples
assert_eq!(flat_tree::Iterator::new(0).right_span(), 0); assert_eq!(flat_tree::Iterator::new(1).right_span(), 2); assert_eq!(flat_tree::Iterator::new(3).right_span(), 6); assert_eq!(flat_tree::Iterator::new(23).right_span(), 30); assert_eq!(flat_tree::Iterator::new(27).right_span(), 30);
pub fn left_child(&mut self) -> usize
[src]
[−]
pub fn left_child(&mut self) -> usize
Get the left_child for the current position and move the cursor.
Examples
assert_eq!(flat_tree::Iterator::new(1).left_child(), 0); assert_eq!(flat_tree::Iterator::new(3).left_child(), 1); assert_eq!(flat_tree::Iterator::new(7).left_child(), 3);
pub fn right_child(&mut self) -> usize
[src]
[−]
pub fn right_child(&mut self) -> usize
Get the right_child for the current position and move the cursor.
Examples
assert_eq!(flat_tree::Iterator::new(1).right_child(), 2); assert_eq!(flat_tree::Iterator::new(3).right_child(), 5); assert_eq!(flat_tree::Iterator::new(7).right_child(), 11);