[][src]Struct permutator::HeapPermutationCellIter

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

Heap's permutation in Rc<RefCell<>> mimic Iterator style. It provides another choice for user that want to share permutation result but doesn't want to clone it for each share. It also doesn't create new result on each iteration unlike other object that implement Iterator trait.

Rationale

Unlike all other struct, HeapPermutationIterator permute value in place. If HeapPermutationIterator struct implement IteratorCell itself will result in the data inside struct left unused. This struct introduce the same concept to other struct that implement IteratorCell, to be able to easily share result with as less performance overhead as possible.

The implementation take Rc<RefCell<&mut [T]>> instead of regular slice like other permutation struct. It implements Iterator trait with empty associated type because it doesn't return value. It permutes the data in place thus every owner of Rc<RefCell<&mut [T]>> will always has an up-to-date slice.

Examples

Iterator style usage example:

   use permutator::HeapPermutationCellIter;
   use std::cell::RefCell;
   use std::rc::Rc;
   use std::time::{Instant};
   let data : &mut [i32] = &mut [1, 2, 3, 4, 5];
   let shared = Rc::new(RefCell::new(data));
   let mut permutator = HeapPermutationCellIter::new(Rc::clone(&shared));
   println!("0:{:?}", &*shared.borrow());
   let timer = Instant::now();
   let mut counter = 1;

   for _ in permutator { // it return empty
       println!("{}:{:?}", counter, &*shared.borrow());
       counter += 1;
   }
 
   // or use iterator related functional approach like line below.
   // permutator.into_iter().for_each(|_| {
   //     println!("{}:{:?}", counter, &*data.borrow());
   //     counter += 1;
   // });

   println!("Done {} permutations in {:?}", counter, timer.elapsed());

See

Methods

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

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

Construct a new permutation iterator. Note: the provided parameter will get mutated in placed at first call to next.

Trait Implementations

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

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

type Item = ()

The type of the elements being iterated over.

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

fn reset(&mut self)[src]

Reset this permutator so calling next will continue permutation on current permuted data. It will not reset permuted data.

Auto Trait Implementations

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

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

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

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

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