[][src]Struct permutator::SelfCartesianProductCellIter

pub struct SelfCartesianProductCellIter<'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::SelfCartesianProductCellIter;
   use std::cell::RefCell;
   use std::rc::Rc;
   use std::time::Instant;
   let data : &[usize] = &[1, 2, 3];
   let n = 3;
   let result : &mut[&usize] = &mut vec![&data[0]; n];
   let shared = Rc::new(RefCell::new(result));
   let cart = SelfCartesianProductCellIter::new(&data, n, Rc::clone(&shared));
   let mut counter = 0;
   let timer = Instant::now();

   for _ in cart {
       // println!("{:?}", &*shared.borrow());
       counter += 1;
   }
 
   // or functional style like the line below
   // cart.into_iter().for_each(|_| {/* 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> SelfCartesianProductCellIter<'a, T> where
    T: 'a, 
[src]

Important traits for SelfCartesianProductCellIter<'a, T>
pub fn new(
    domain: &'a [T],
    n: usize,
    result: Rc<RefCell<&'a mut [&'a T]>>
) -> SelfCartesianProductCellIter<'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. This is equals to create a domains contains cloned domain 3 time.
  • n the size of product. For example n = 3 means create a cartesian product over domain paremeter 3 times.
  • result an Rc<RefCell<&mut[&T]>> to store each product

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

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

type Item = ()

The type of the elements being iterated over.

fn next(&mut self) -> Option<()>[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 SelfCartesianProductCellIter<'a, T>[src]

Auto Trait Implementations

impl<'a, T> !RefUnwindSafe for SelfCartesianProductCellIter<'a, T>

impl<'a, T> !Send for SelfCartesianProductCellIter<'a, T>

impl<'a, T> !Sync for SelfCartesianProductCellIter<'a, T>

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

impl<'a, T> !UnwindSafe for SelfCartesianProductCellIter<'a, T>

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.