INGOR
|
Combination related routines. More...
#include <math/ytCombo.h>
Public Member Functions | |
uint64_t | ytCombo_choose (int n, int k) |
Calculates the number of combinations of n things taken k at a time (binomial coefficient). | |
int | ytCombo_generate (int n, int k, int *ar) |
Generates the combination. | |
void | ytCombo_indexTable (int n, uint64_t *table) |
Generates the index table for ytCombo routines. | |
uint64_t | ytCombo_index (int n, int c, const int *ar, const uint64_t *table, int tn) |
Calculates the index for the given combination. | |
void | ytCombo_combination (int n, int k, uint64_t index, int *ar, const uint64_t *table, int tn) |
Obtain the combination corresponding to the given index. | |
void | ytCombo_combination2 (int n, int k, uint64_t index, int *ar, const int *a, const uint64_t *table, int tn) |
Obtain the combination corresponding to the given index. | |
void | ytCombo_combination3 (int n, int k, uint64_t index, int *ar, const int *a, const int *b, const uint64_t *table, int tn) |
Obtain the combination corresponding to the given index. | |
Combination related routines.
uint64_t ytCombo_choose | ( | int | n, |
int | k | ||
) |
Calculates the number of combinations of n things taken k at a time (binomial coefficient).
This is the C implementation of ACM Algorithm 160.
n | |
k |
void ytCombo_combination | ( | int | n, |
int | k, | ||
uint64_t | index, | ||
int * | ar, | ||
const uint64_t * | table, | ||
int | tn | ||
) |
Obtain the combination corresponding to the given index.
This is the inverse function of ytCombo_index().
tn | table size specified to ytCombo_indexTable(). |
void ytCombo_combination2 | ( | int | n, |
int | k, | ||
uint64_t | index, | ||
int * | ar, | ||
const int * | a, | ||
const uint64_t * | table, | ||
int | tn | ||
) |
Obtain the combination corresponding to the given index.
This is the inverse function of ytCombo_index().
tn | table size specified to combo_indexTable(). |
void ytCombo_combination3 | ( | int | n, |
int | k, | ||
uint64_t | index, | ||
int * | ar, | ||
const int * | a, | ||
const int * | b, | ||
const uint64_t * | table, | ||
int | tn | ||
) |
Obtain the combination corresponding to the given index.
This is the inverse function of ytCombo_index().
tn | table size specified to combo_indexTable(). |
int ytCombo_generate | ( | int | n, |
int | k, | ||
int * | ar | ||
) |
Generates the combination.
This generates the combination of n things taken k at a time in lexicographical order from the previouly generated combination.
To generate the first combination, set -1 for the first positions of ar.
n | |
k | |
ar |
uint64_t ytCombo_index | ( | int | n, |
int | c, | ||
const int * | ar, | ||
const uint64_t * | table, | ||
int | tn | ||
) |
Calculates the index for the given combination.
Note that this returns the reverse order (index) of the combination. To obtain the normal index, calculate (choose(n, c) - \t id) where \t id is the reverse index returned by this function.
ar | sorted list (combination) of values. |
table | index table calculated by ytCombo_index_table(). |
tn | table size used to calculate table by ytCombo_index_table(). |
void ytCombo_indexTable | ( | int | n, |
uint64_t * | table | ||
) |