[][src]Struct permutator::CartesianProductIterator

pub struct CartesianProductIterator<'a, T> where
    T: 'a, 
{ /* fields omitted */ }

Generate a cartesian product between given domains in an iterator style. The struct implement Iterator trait so it can be used in Iterator style. The struct provide into_iter() function that return itself.

Example

   use permutator::CartesianProductIterator;
   use std::time::Instant;
   let data : &[&[usize]] = &[&[1, 2, 3], &[4, 5, 6], &[7, 8, 9]];
   let cart = CartesianProductIterator::new(&data);
   let mut counter = 0;
   let timer = Instant::now();

   for p in cart {
       // println!("{:?}", p);
       counter += 1;
   }
 
   // or functional style like the line below
   // cart.into_iter().for_each(|p| {/* do something iterative style */});

   assert_eq!(data.iter().fold(1, |cum, domain| {cum * domain.len()}), counter);
   println!("Total {} products done in {:?}", counter, timer.elapsed());

Methods

impl<'a, T> CartesianProductIterator<'a, T> where
    T: 'a, 
[src]

Important traits for CartesianProductIterator<'a, T>
pub fn new(domains: &'a [&[T]]) -> CartesianProductIterator<'a, T>[src]

Create a new Cartesian product iterator that create a product between each domain inside domains.

Parameters

  • domains A slice of domains to create a cartesian product between each domain inside it.

Return

An object that can be iterate over in iterator style.

pub fn into_iter(self) -> Self[src]

Consume itself and return without modify it. Typical usecase is for p in ref_to_this.into_iter() {} or ref_to_this.into_iter().for_each(|p| {/* Do something with product */});

Trait Implementations

impl<'a, T> ExactSizeIterator for CartesianProductIterator<'a, T>[src]

impl<'a, T> Iterator for CartesianProductIterator<'a, T>[src]

type Item = Vec<&'a T>

The type of the elements being iterated over.

fn next(&mut self) -> Option<Vec<&'a T>>[src]

Each iteration return a new Vec contains borrowed element inside an Option. The result can be collected by using collect method from Iterator trait.

Return None when exhausted.

impl<'a, T> IteratorReset for CartesianProductIterator<'a, T>[src]

Auto Trait Implementations

impl<'a, T> RefUnwindSafe for CartesianProductIterator<'a, T> where
    T: RefUnwindSafe

impl<'a, T> Send for CartesianProductIterator<'a, T> where
    T: Sync

impl<'a, T> Sync for CartesianProductIterator<'a, T> where
    T: Sync

impl<'a, T> Unpin for CartesianProductIterator<'a, T>

impl<'a, T> UnwindSafe for CartesianProductIterator<'a, T> where
    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, 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.