Struct Iter

Source
pub struct Iter<T: BorrowMut<[usize]>> { /* private fields */ }
Expand description

Iterates over all k-combinations.

The k-combinations are iterated in value order:

let mut iter = Iter::new(k);
for i in 0 .. combination(n, k) {
    assert_eq!(encode(iter.get()), i);
    iter.advance();
}

§Examples

To iterate over all k-combinations in a set of n elements:

let mut iter = Iter::new(k);
for _ in 0 .. combination(n, k) {
    process(iter.get());
    iter.advance();
}

In a no-std environment, you can pass a buffer of size K:

let mut buffer = [0usize; K];
let mut iter = Iter::new_with_buffer(&mut buffer[..]);

Implementations§

Source§

impl Iter<Vec<usize>>

Source

pub fn new(k: usize) -> Iter<Vec<usize>>

Constructs an iterator.

Source§

impl<T: BorrowMut<[usize]>> Iter<T>

Source

pub fn new_with_buffer(buffer: T) -> Iter<T>

Constructs an iterator with a buffer.

Source

pub fn new_from(xs: T) -> Iter<T>

Constructs an iterator starting from a given k-combination.

§Panics

Panics in debug mode if xs is not increasing.

Source

pub fn get(&self) -> &[usize]

Returns the current combination.

Source

pub fn advance(&mut self)

Advances to the next combination.

Auto Trait Implementations§

§

impl<T> Freeze for Iter<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Iter<T>
where T: RefUnwindSafe,

§

impl<T> Send for Iter<T>
where T: Send,

§

impl<T> Sync for Iter<T>
where T: Sync,

§

impl<T> Unpin for Iter<T>
where T: Unpin,

§

impl<T> UnwindSafe for Iter<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.