gitql_core/
combinations_generator.rs

1/// Return a list of all non empty and unique combinations
2pub fn generate_list_of_all_combinations(n: usize) -> Vec<Vec<usize>> {
3    let mut result = Vec::with_capacity((2 << n) - 1);
4    let mut current = Vec::with_capacity(n);
5    generate_indices_combination(n, 0, &mut current, &mut result);
6    result
7}
8
9fn generate_indices_combination(
10    n: usize,
11    start: usize,
12    current: &mut Vec<usize>,
13    result: &mut Vec<Vec<usize>>,
14) {
15    if !current.is_empty() {
16        result.push(current.clone());
17    }
18
19    for i in start..n {
20        current.push(i);
21        generate_indices_combination(n, i + 1, current, result);
22        current.pop();
23    }
24}