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

Constructs an iterator.

Constructs an iterator with a buffer.

Constructs an iterator starting from a given k-combination.

Panics

Panics in debug mode if xs is not increasing.

Returns the current combination.

Advances to the next combination.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.