occ
Loading...
Searching...
No Matches
occ::core::Combinations Class Reference

Class to generate all possible combinations of a integers. More...

#include <combinations.h>

Public Types

using Result = std::vector< int >
 

Public Member Functions

 Combinations (int n, int r)
 Combinations constructor.
 
bool is_completed () const
 Check if the sequence of unique combinations is exhausted/completed.
 
int num_generated () const
 The current total count of unique combinations generated.
 
const Resultnext ()
 The next combination in the sequence.
 

Detailed Description

Class to generate all possible combinations of a integers.

The role of the Combinations class is to serve as a generator for all possible combinations (i.e. permutations where order is not important) of integers up to some maximum, of a specific length.

Member Typedef Documentation

◆ Result

using occ::core::Combinations::Result = std::vector<int>

Constructor & Destructor Documentation

◆ Combinations()

occ::core::Combinations::Combinations ( int  n,
int  r 
)

Combinations constructor.

Parameters
nmaximum possible value for the integer (exclusive, i.e. range will be [0,n))
rlength of the combination sequences

Internally, combinations holds a std::vector<int> of length r, and returns a const reference to this for each generated sequence.

For example to generate all combinations of length 3 of containing integers in the range [0, 10) i.e. up to 9, you would call

Combinations com(10, 3);
while(!com.is_completed()) {
const auto &c = com.next();
// do something with c
}
// the total number of combinations generated
int count = com.num_generated();
Class to generate all possible combinations of a integers.
Definition combinations.h:15

Member Function Documentation

◆ is_completed()

bool occ::core::Combinations::is_completed ( ) const

Check if the sequence of unique combinations is exhausted/completed.

Returns
True if there are no more combinations to generate

◆ next()

const Result & occ::core::Combinations::next ( )

The next combination in the sequence.

Returns
a const reference to a std::vector<int> containing the next combination.

◆ num_generated()

int occ::core::Combinations::num_generated ( ) const

The current total count of unique combinations generated.

Returns
an int representing the number of combinations generated.

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