emk_comb_gen

Function emk_comb_gen 

Source
pub fn emk_comb_gen(n: usize, k: usize) -> GenBoxed<(usize, usize)>
Expand description

Generate all combinations by homogeneous revolving-door

The emk_comb_gen function generates all combinations by using a homogeneous revolving-door algorithm.

Arguments:

  • n: The parameter n represents the total number of elements in the combination set. It determines the range of indices that can be used in the combinations.
  • k: The parameter k represents the number of elements that will be swapped in each combination.

Returns:

The function emk_gen returns a GenBoxed<(usize, usize)>, which is a boxed generator that yields tuples of two usize values.

ยงExamples

use ecgen::emk_comb_gen;
  
let mut combin = [1, 1, 0];
println!("{:?}", combin);
let mut cnt = 1;
for (i, j) in emk_comb_gen(3, 2) {
    combin.swap(i, j);
    println!("{:?}", combin);
    cnt += 1;
}

assert_eq!(cnt, 3);