-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcombination_iterator.h
43 lines (38 loc) · 1.17 KB
/
combination_iterator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Licensed under the MIT License.
#include "object.h"
#include <stdbool.h>
#include <stddef.h>
/** Iterates over all unique `k`-element subsets of the interval [1, `n`]. */
struct CombinationIterator
{
int* subset;
int i;
int k;
int n;
bool end;
};
/** Iterates over all unique `k`-element subsets of the interval [1, `n`]. */
typedef struct CombinationIterator* CombinationIterator;
/**
* Provides an iterator over the unique `k`-element subsets of the interval
* [1, `n`].
*
* @param iterator when this method returns, contains the iterator. This
* argument is passed uninitialized.
* @param subset when this method returns, contains the subset. This
* argument is passed as an uninitialized `k`-element array for
* which the caller is responsible.
* @param n the cardinality of the superset.
* @param k the cardinality of the subset.
*/
void combination_begin(
CombinationIterator iterator,
int subset[],
int n,
int k);
/**
* Advances the iterator to the next unique `k`-element subset.
*
* @param iterator the iterator.
*/
void combination_next(CombinationIterator iterator);