[][src]Struct permutator::SelfCartesianProductRefIter

pub struct SelfCartesianProductRefIter<'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::SelfCartesianProductRefIter;
   use std::time::Instant;
   let data : &[usize] = &[1, 2, 3];
   let n = 3;
   let result : &mut[&usize] = &mut vec![&data[0]; n];
   let shared = result as *mut[&usize];
    
   unsafe {
        let cart = SelfCartesianProductRefIter::new(&data, n, result);
        let mut counter = 0;
        let timer = Instant::now();

        for _ in cart {
            // println!("{:?}", &*shared);
            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> SelfCartesianProductRefIter<'a, T> where
    T: 'a, 
[src]

Important traits for SelfCartesianProductRefIter<'a, T>
pub unsafe fn new(
    domain: &'a [T],
    n: usize,
    result: *mut [&'a T]
) -> SelfCartesianProductRefIter<'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 *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 SelfCartesianProductRefIter<'a, T>[src]

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

Auto Trait Implementations

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

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

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

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

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