[][src]Struct permutator::GosperCombinationIterator

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

Deprecated

This iterator family is now deprecated. Consider using LargeCombinationIterator instead. This is because current implementation need to copy every ref on every iteration which is inefficient. On uncontroll test environment, this iterator take 18.98s to iterate over 30,045,015 combinations. The LargeCombinationIterator took only 2.77s. If no more efficient implementation is available for some certain time period, this function will be officially mark with #[deprecated].

Create a combination iterator. It use Gosper's algorithm to pick a combination out of given data. The produced combination provide no lexicographic order.

The returned combination will be a reference into given data. Each combination return from iterator will be a new Vec. It's safe to hold onto a combination or collect it.

Examples

Given slice of [1, 2, 3, 4, 5]. It will produce following combinations: [1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4], [1, 2, 5], [1, 3, 5], [2, 3, 5], [1, 4, 5], [2, 4, 5], [3, 4, 5] Here's an example of code printing above combination.

   use permutator::GosperCombinationIterator;
   use std::time::{Instant};
   let gosper = GosperCombinationIterator::new(&[1, 2, 3, 4, 5], 3);
   let mut counter = 0;
   let timer = Instant::now();

   for combination in gosper {
       println!("{}:{:?}", counter, combination);
       counter += 1;
   }

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

Limitation

Gosper algorithm need to know the MSB (most significant bit). The current largest known MSB data type is u128. This make the implementation support up to 128 elements slice.

See

Methods

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

pub fn new(data: &[T], r: usize) -> GosperCombinationIterator<T>[src]

Create new combination generator using Gosper's algorithm. r shall be smaller than data.len().

Note: It perform no check on given parameter. If r is larger than length of data then iterate over it will not occur. The iteration will be end upon enter.

pub fn len(&self) -> usize[src]

Total number of combinations this iterate can return. It will equals to n!/((n-r)!*r!)

pub fn reset(&mut self)[src]

Trait Implementations

impl<'a, T> IntoIterator for GosperCombinationIterator<'a, T>[src]

type Item = Vec<&'a T>

The type of the elements being iterated over.

type IntoIter = CombinationIterator<'a, T>

Which kind of iterator are we turning this into?

Auto Trait Implementations

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

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

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

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

impl<'a, T> UnwindSafe for GosperCombinationIterator<'a, T> where
    T: RefUnwindSafe

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.