[][src]Struct flat_tree::Iterator

pub struct Iterator { /* fields omitted */ }

Iterator over a flat-tree.

Methods

impl Iterator[src]

pub fn new(index: u64) -> Self[src]

Create a new iterator.

Examples

use flat_tree::Iterator;
assert_eq!(Iterator::new(0).take(3).collect::<Vec<u64>>(), [2, 4, 6]);

pub fn index(&self) -> u64[src]

Get the current index.

pub fn offset(&self) -> u64[src]

Get the current offset.

pub fn factor(&self) -> u64[src]

Get the current factor.

pub fn seek(&mut self, index: u64)[src]

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]

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]

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) -> u64[src]

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) -> u64[src]

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) -> u64[src]

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) -> u64[src]

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) -> u64[src]

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) -> u64[src]

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) -> u64[src]

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);

Trait Implementations

impl Debug for Iterator[src]

impl Default for Iterator[src]

impl Iterator for Iterator[src]

type Item = u64

The type of the elements being iterated over.

Auto Trait Implementations

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<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

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.