Public Member Functions | Private Member Functions | Private Attributes | List of all members
gnsstk::Combinations Class Reference

Detailed Description

Class Combinations will compute C(n,k), all the combinations of n things taken k at a time (where k <= n). Let n 'things' be indexed by i (i=0...n-1), e.g. stored in an array of length n. This class computes C(n,k) as sets of k indexes into the 'things' array. These indexes are accessible via member functions Selection() or isSelected(). Next() computes the next combination until there are no more (when it returns -1).

Definition at line 58 of file Combinations.hpp.

#include <Combinations.hpp>

Public Member Functions

 Combinations (const Combinations &right) noexcept
 copy constructor More...
 
 Combinations (int N, int K)
 
 Combinations (void) noexcept
 Default constructor. More...
 
bool isSelected (int j) noexcept
 
int Next (void) noexcept
 
Combinationsoperator= (const Combinations &right) noexcept
 Assignment operator. More...
 
int Selection (int j) noexcept
 

Private Member Functions

int Increment (int j) noexcept
 Recursive function to increment Index[j]. More...
 
void init (int N, int K)
 

Private Attributes

std::vector< int > Index
 
int k
 
int n
 combinations of n things taken k at a time More...
 
int nc
 number of combinations computed so far More...
 

Constructor & Destructor Documentation

◆ Combinations() [1/3]

gnsstk::Combinations::Combinations ( void  )
inlinenoexcept

Default constructor.

Definition at line 61 of file Combinations.hpp.

◆ Combinations() [2/3]

gnsstk::Combinations::Combinations ( int  N,
int  K 
)
inline

Constructor for C(n,k) = combinations of n things taken k at a time (k <= n)

Exceptions
Exceptionon invalid input (k>n).

Definition at line 69 of file Combinations.hpp.

◆ Combinations() [3/3]

gnsstk::Combinations::Combinations ( const Combinations right)
inlinenoexcept

copy constructor

Definition at line 73 of file Combinations.hpp.

Member Function Documentation

◆ Increment()

int gnsstk::Combinations::Increment ( int  j)
inlineprivatenoexcept

Recursive function to increment Index[j].

Definition at line 133 of file Combinations.hpp.

◆ init()

void gnsstk::Combinations::init ( int  N,
int  K 
)
inlineprivate

The initialization routine used by constructors.

Exceptions
Exceptionon invalid input (k>n or either n or k < 0).

Definition at line 117 of file Combinations.hpp.

◆ isSelected()

bool gnsstk::Combinations::isSelected ( int  j)
inlinenoexcept

Return true if the given index j (0 <= j < n) is currently selected (i.e. if j = Selection(i) for some i)

Definition at line 106 of file Combinations.hpp.

◆ Next()

int gnsstk::Combinations::Next ( void  )
inlinenoexcept

Compute the next combination, returning the number of combinations computed so far; if there are no more combinations, return -1.

Definition at line 90 of file Combinations.hpp.

◆ operator=()

Combinations& gnsstk::Combinations::operator= ( const Combinations right)
inlinenoexcept

Assignment operator.

Definition at line 80 of file Combinations.hpp.

◆ Selection()

int gnsstk::Combinations::Selection ( int  j)
inlinenoexcept

Return index i (0 <= i < n) of jth selection (0 <= j < k); if j is out of range, return -1.

Definition at line 98 of file Combinations.hpp.

Member Data Documentation

◆ Index

std::vector<int> gnsstk::Combinations::Index
private

Index[j] = index of jth selection (j=0...k-1; I[j]=0...n-1)

Definition at line 150 of file Combinations.hpp.

◆ k

int gnsstk::Combinations::k
private

Definition at line 149 of file Combinations.hpp.

◆ n

int gnsstk::Combinations::n
private

combinations of n things taken k at a time

Definition at line 149 of file Combinations.hpp.

◆ nc

int gnsstk::Combinations::nc
private

number of combinations computed so far

Definition at line 148 of file Combinations.hpp.


The documentation for this class was generated from the following file:


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:44