PARP Research Group | Universidad de Murcia |
QVCombinationIterator Class Reference
|
Public Member Functions | |
QVCombinationIterator () | |
Constructs a default combination iterator. | |
QVCombinationIterator (const QVCombinationIterator &combinationIterator) | |
Constructs a new combination iterator that is a copy of other. | |
QVCombinationIterator (const int numElements, const int elementsXSet) | |
Constructs a new combination iterator with a specifics cardinallity and subset's size. | |
virtual bool | increment () |
Obtains the next subset of the iteration, indicating if the iteration has finished. | |
QVCombinationIterator & | operator++ () |
infix ++ operator. | |
void | operator++ (int) |
postfix ++ operator. | |
double | getSubsetNumber () const |
Obtains the amount of possible subsets of a given size and cardinallity. | |
bool | finished () const |
Indicate if the iteration has finished. | |
int | firstIndex () const |
Obtains the first element of the current subset. | |
int | lastIndex () const |
Obtains the last element of the current subset. | |
int | getSetCardinallity () const |
Obtains the cardinallity of the combination. | |
int | getSubsetsSize () const |
Obtains the subset's size. |
Iterator over all possible combinations over a set.
Generates a sequence containing all the possible subsets of a given cardinallity, from a original set. This set will be the integer numbers from zero to an specified value, so the elements of the original set should be contained in a QList or a QVector.
Use examples: The following examples show how to use this iterator.
QVCombinationIterator combination(7, 3); while(!combination.finished()) { std::cout << combination; combination.increment(); }
QVCombinationIterator combination(7, 3); do std::cout << combination; while(combination.increment());
For flavour:
for (QVCombinationIterator combination(7, 3); !combination.finished(); combination++) std::cout << combination;
All of the previous examples will print the resulting combination of elements from the original set, producing the following output:
Combination(3 elements over 7): [0] [1] [2] 3 4 5 6 Combination(3 elements over 7): [0] [1] 2 [3] 4 5 6 Combination(3 elements over 7): [0] 1 [2] [3] 4 5 6 Combination(3 elements over 7): 0 [1] [2] [3] 4 5 6 Combination(3 elements over 7): [0] [1] 2 3 [4] 5 6 Combination(3 elements over 7): [0] 1 [2] 3 [4] 5 6 Combination(3 elements over 7): 0 [1] [2] 3 [4] 5 6 Combination(3 elements over 7): [0] 1 2 [3] [4] 5 6 Combination(3 elements over 7): 0 [1] 2 [3] [4] 5 6 Combination(3 elements over 7): 0 1 [2] [3] [4] 5 6 Combination(3 elements over 7): [0] [1] 2 3 4 [5] 6 Combination(3 elements over 7): [0] 1 [2] 3 4 [5] 6 Combination(3 elements over 7): 0 [1] [2] 3 4 [5] 6 Combination(3 elements over 7): [0] 1 2 [3] 4 [5] 6 Combination(3 elements over 7): 0 [1] 2 [3] 4 [5] 6 Combination(3 elements over 7): 0 1 [2] [3] 4 [5] 6 Combination(3 elements over 7): [0] 1 2 3 [4] [5] 6 Combination(3 elements over 7): 0 [1] 2 3 [4] [5] 6 Combination(3 elements over 7): 0 1 [2] 3 [4] [5] 6 Combination(3 elements over 7): 0 1 2 [3] [4] [5] 6 Combination(3 elements over 7): [0] [1] 2 3 4 5 [6] Combination(3 elements over 7): [0] 1 [2] 3 4 5 [6] Combination(3 elements over 7): 0 [1] [2] 3 4 5 [6] Combination(3 elements over 7): [0] 1 2 [3] 4 5 [6] Combination(3 elements over 7): 0 [1] 2 [3] 4 5 [6] Combination(3 elements over 7): 0 1 [2] [3] 4 5 [6] Combination(3 elements over 7): [0] 1 2 3 [4] 5 [6] Combination(3 elements over 7): 0 [1] 2 3 [4] 5 [6] Combination(3 elements over 7): 0 1 [2] 3 [4] 5 [6] Combination(3 elements over 7): 0 1 2 [3] [4] 5 [6] Combination(3 elements over 7): [0] 1 2 3 4 [5] [6] Combination(3 elements over 7): 0 [1] 2 3 4 [5] [6] Combination(3 elements over 7): 0 1 [2] 3 4 [5] [6] Combination(3 elements over 7): 0 1 2 [3] 4 [5] [6] Combination(3 elements over 7): 0 1 2 3 [4] [5] [6]
Meaning the selected elements surrounded by brackets for each combination. The index for each one of the selected elements can be accessed with the operator[]. The number of elements accessible with it can be obtained with method getSubsetsSize(), which is the size of the subsets.
Definition at line 110 of file qvcombinationiterator.h.
QVCombinationIterator::QVCombinationIterator | ( | ) | [inline] |
Constructs a default combination iterator.
Generate a combination iterator with one element, and its internal state is defined to finished.
Definition at line 120 of file qvcombinationiterator.h.
QVCombinationIterator::QVCombinationIterator | ( | const QVCombinationIterator & | combinationIterator | ) | [inline] |
Constructs a new combination iterator that is a copy of other.
combinationIterator | the combination iterator to be copied. |
Definition at line 126 of file qvcombinationiterator.h.
QVCombinationIterator::QVCombinationIterator | ( | const int | numElements, | |
const int | elementsXSet | |||
) | [inline] |
Constructs a new combination iterator with a specifics cardinallity and subset's size.
The new combination iterator contains the first subset of the iteration.
numElements | the cardinallity of the susets, must be > 0. | |
elementsXSet | the subset's size, must be <= numElements. |
Definition at line 135 of file qvcombinationiterator.h.
bool QVCombinationIterator::increment | ( | ) | [virtual] |
Obtains the next subset of the iteration, indicating if the iteration has finished.
Returns a true valor until it obtains the last subset, the following times it returns false valor and passes to an undefined subset.
Definition at line 27 of file qvcombinationiterator.cpp.
Referenced by operator++().
QVCombinationIterator& QVCombinationIterator::operator++ | ( | ) | [inline] |
void QVCombinationIterator::operator++ | ( | int | ) | [inline] |
postfix ++ operator.
Increment the iteration.
Definition at line 163 of file qvcombinationiterator.h.
double QVCombinationIterator::getSubsetNumber | ( | ) | const [inline] |
Obtains the amount of possible subsets of a given size and cardinallity.
The increment function returns a true valor the first getSubsetNmber - 1 invocations.
Definition at line 169 of file qvcombinationiterator.h.
bool QVCombinationIterator::finished | ( | ) | const [inline] |
Indicate if the iteration has finished.
Definition at line 173 of file qvcombinationiterator.h.
int QVCombinationIterator::firstIndex | ( | ) | const [inline] |
Obtains the first element of the current subset.
Definition at line 177 of file qvcombinationiterator.h.
int QVCombinationIterator::lastIndex | ( | ) | const [inline] |
Obtains the last element of the current subset.
Definition at line 181 of file qvcombinationiterator.h.
int QVCombinationIterator::getSetCardinallity | ( | ) | const [inline] |
Obtains the cardinallity of the combination.
Definition at line 185 of file qvcombinationiterator.h.
Referenced by operator<<().
int QVCombinationIterator::getSubsetsSize | ( | ) | const [inline] |
Obtains the subset's size.
Definition at line 189 of file qvcombinationiterator.h.
Referenced by operator<<().