[][src]Struct permutator::HeapPermutationRefIter

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

An unsafe Heap's permutation in iterator style implementation.

Examples

  • Iterator style usage example:
   use permutator::HeapPermutationRefIter;
   use std::time::{Instant};
   let data : &mut[i32] = &mut [1, 2, 3, 4, 5];
   println!("0:{:?}", data);
   unsafe {
        let mut permutator = HeapPermutationRefIter::new(data as *mut[i32]);
        let timer = Instant::now();
        let mut counter = 1;

        for permutated in permutator {
            println!("{}:{:?}", counter, permutated);
            counter += 1;
        }
 
        // or use iterator related functional approach like line below.
        // permutator.into_iter().for_each(|permutated| {counter += 1;});

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

In test environment, given a slice of 8 strings. It has about 40 characters each. This implementation is about 70 times (33ms vs 0.47ms) faster than a HeapPermutation iteration. This is because each next function doesn't clone/copy the value.
However, this implementation limited the way to use data because each iteration permute the result in place. It require user to manually sync the share operation.

See

Methods

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

Important traits for HeapPermutationRefIter<'a, T>
pub unsafe fn new(data: *mut [T]) -> HeapPermutationRefIter<'a, T>[src]

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

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

Consume itself immediately return it. It mimic how IntoIterator trait perform except that this struct itself implement Iterator trait.

Trait Implementations

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

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

type Item = ()

The type of the elements being iterated over.

impl<'a, T> IteratorReset for HeapPermutationRefIter<'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 HeapPermutationRefIter<'a, T> where
    T: RefUnwindSafe

impl<'a, T> Send for HeapPermutationRefIter<'a, T> where
    T: Send

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

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

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