[][src]Struct traversal::DftLongestPaths

pub struct DftLongestPaths<'a, T, F, I> where
    T: ?Sized,
    F: FnMut(&'a T) -> I,
    I: Iterator<Item = &'a T>, 
{ /* fields omitted */ }

Produces the longest paths using Depth-First Traversal (in Pre-Order).

Cycles

DftLongestPaths does not handle cycles. If any cycles are present, then DftLongestPaths will result in an infinite (never ending) Iterator.

Example

use traversal::DftLongestPaths;

struct Node(&'static str, &'static [Node]);

let tree = Node("A", &[
    Node("B", &[
        Node("C", &[]),
        Node("D", &[])
    ]),
    Node("E", &[
        Node("F", &[]),
        Node("G", &[])
    ]),
]);

// `&tree` represents the root `Node`.
// The `FnMut(&Node) -> Iterator<Item = &Node>` returns
// an `Iterator` to get the child `Node`s.
let iter = DftLongestPaths::new(&tree, |node| node.1.iter());

// Map `Iterator<Item = Vec<&Node>>` into `Iterator<Item = Vec<&str>>`
let mut iter = iter.map(|path| path.iter().map(|node| node.0).collect::<Vec<_>>());

assert_eq!(iter.next(), Some(vec!["A", "B", "C"]));
assert_eq!(iter.next(), Some(vec!["A", "B", "D"]));
assert_eq!(iter.next(), Some(vec!["A", "E", "F"]));
assert_eq!(iter.next(), Some(vec!["A", "E", "G"]));
assert_eq!(iter.next(), None);

Methods

impl<'a, T, F, I> DftLongestPaths<'a, T, F, I> where
    T: ?Sized,
    F: FnMut(&'a T) -> I,
    I: Iterator<Item = &'a T>, 
[src]

pub fn new(root: &'a T, iter_children: F) -> Self[src]

Creates a DftLongestPaths, where root is the starting Node.

The iter_children FnMut is (lazily) called for each Node as needed, where the returned Iterator produces the child Nodes for the given Node.

See DftLongestPaths for more information.

"FnOnce"

The FnMut is a FnOnce from the point-of-view of a Node, as iter_children is at most called once for each individual Node.

FusedIterator

While DftLongestPaths does not require FusedIterator, it assumes that no Nodes are produced after a None.

Trait Implementations

impl<'a, T, F: Clone, I: Clone> Clone for DftLongestPaths<'a, T, F, I> where
    T: Clone + ?Sized,
    F: FnMut(&'a T) -> I,
    I: Iterator<Item = &'a T>, 
[src]

impl<'a, T, F, I> FusedIterator for DftLongestPaths<'a, T, F, I> where
    T: ?Sized,
    F: FnMut(&'a T) -> I,
    I: Iterator<Item = &'a T>, 
[src]

impl<'a, T, F, I> Iterator for DftLongestPaths<'a, T, F, I> where
    T: ?Sized,
    F: FnMut(&'a T) -> I,
    I: Iterator<Item = &'a T>, 
[src]

type Item = Vec<&'a T>

The type of the elements being iterated over.

Auto Trait Implementations

impl<'a, T: ?Sized, F, I> RefUnwindSafe for DftLongestPaths<'a, T, F, I> where
    F: RefUnwindSafe,
    T: RefUnwindSafe

impl<'a, T: ?Sized, F, I> Send for DftLongestPaths<'a, T, F, I> where
    F: Send,
    T: Sync

impl<'a, T: ?Sized, F, I> Sync for DftLongestPaths<'a, T, F, I> where
    F: Sync,
    T: Sync

impl<'a, T: ?Sized, F, I> Unpin for DftLongestPaths<'a, T, F, I> where
    F: Unpin

impl<'a, T: ?Sized, F, I> UnwindSafe for DftLongestPaths<'a, T, F, I> where
    F: UnwindSafe,
    T: RefUnwindSafe

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> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.