[][src]Struct permutator::SelfCartesianProductIterator

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

Generate a cartesian product on itself 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::SelfCartesianProductIterator;
   use std::time::Instant;
   let data : &[usize] = &[1, 2, 3];
   let n = 3;
   let cart = SelfCartesianProductIterator::new(&data, n);
   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.len().pow(n as u32), counter);
   println!("Total {} products done in {:?}", counter, timer.elapsed());

Methods

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

Important traits for SelfCartesianProductIterator<'a, T>
pub fn new(domain: &'a [T], n: usize) -> SelfCartesianProductIterator<'a, T>[src]

Create a new Cartesian product iterator that create a product on itself n times.

Parameters

  • domain A slice of domains to create a cartesian product between each domain inside it.
  • n the size of product. For example n = 3 means create a cartesian product over domain paremeter 3 times. This is equals to create a domains contains cloned domain 3 time.

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 SelfCartesianProductIterator<'a, T>[src]

impl<'a, T> Iterator for SelfCartesianProductIterator<'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 SelfCartesianProductIterator<'a, T>[src]

Auto Trait Implementations

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

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

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

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

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