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 parameternrepresents the total number of elements in the combination set. It determines the range of indices that can be used in the combinations.k: The parameterkrepresents 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);