[][src]Struct permutator::CartesianProductCellIter

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

Generate a cartesian product between given domains into Rc<RefCell<&mut [&T]>> in an iterator style. The struct implement Iterator trait so it can be used as Iterator. The struct provide into_iter() function that return itself.

Example

  • Iterator style usage
   use permutator::CartesianProductCellIter;
   use std::cell::RefCell;
   use std::rc::Rc;
   use std::time::Instant;
   let data : Vec<&[usize]> = vec![&[1, 2, 3], &[4, 5, 6], &[7, 8, 9]];
   let mut result : Vec<&usize> = vec![&data[0][0]; data.len()];
   let shared = Rc::new(RefCell::new(result.as_mut_slice()));
   let cart = CartesianProductCellIter::new(&data, 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.iter().fold(1, |cum, domain| {cum * domain.len()}), counter);
   println!("Total {} products done in {:?}", counter, timer.elapsed());

Methods

impl<'a, T> CartesianProductCellIter<'a, T>[src]

Important traits for CartesianProductCellIter<'a, T>
pub fn new(
    data: &'a [&'a [T]],
    result: Rc<RefCell<&'a mut [&'a T]>>
) -> CartesianProductCellIter<'a, T>
[src]

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

Trait Implementations

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

impl<'a, T> Iterator for CartesianProductCellIter<'a, T> where
    T: 'a, 
[src]

type Item = ()

The type of the elements being iterated over.

fn next(&mut self) -> Option<()>[src]

Mimic iterator next function but return value into Rc<RefCell<>> that contains mutable slice. It also return an empty Option to tell caller to distinguish if it's put new value or the iterator itself is exhausted.

Paramerter

  • result An Rc<RefCell<>> contains a mutable slice with length equals to number of domains given in CartesianProductIterator::new(). The value inside result will be updated everytime this function is called until the function return None. The performance using this function is on part with cartesian_cell function on uncontrol test environment.

Return

New cartesian product between each domains inside result parameter and also return Some(()) if result is updated or None when there's no new result.

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

Auto Trait Implementations

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

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

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

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

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