Macaulay2 Engine
Loading...
Searching...
No Matches

◆ Subsets()

Subsets::Subsets ( size_t n,
size_t p )

Definition at line 20 of file comb.cpp.

21{
22 assert(p <= n);
23 // we also need to assert that all values placed are size_t without overflow
24 mTable = newarray(size_t *, p + 1);
25 for (size_t i = 0; i <= p; i++) mTable[i] = newarray_atomic(size_t, n + 1);
26
27 // Now fill in the table completely
28 for (size_t i = 1; i <= mMaxSubsetSize; i++) mTable[i][0] = 0;
29 for (size_t j = 0; j <= mNumElements; j++) mTable[0][j] = 1;
30 for (size_t i = 1; i <= mMaxSubsetSize; i++)
31 for (size_t j = 1; j <= mNumElements; j++)
32 mTable[i][j] = range_safe_add(mTable[i][j - 1], mTable[i - 1][j - 1]);
33}
size_t mNumElements
Definition comb.hpp:125
size_t ** mTable
Definition comb.hpp:124
size_t mMaxSubsetSize
Definition comb.hpp:127
ulong range_safe_add(ulong a, ulong b)
Definition comb.cpp:9
int p
#define newarray(T, len)
Definition newdelete.hpp:82
#define newarray_atomic(T, len)
Definition newdelete.hpp:91

References mMaxSubsetSize, mNumElements, mTable, newarray, newarray_atomic, p, and range_safe_add().