00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024
00025 #include <QVCombinationIterator>
00026
00027 bool QVCombinationIterator::increment()
00028 {
00029 if (endCondition == true)
00030 return false;
00031
00032 const int siz = size();
00033 int pivot = siz-1;
00034
00035
00036 for (int i=0; (pivot == siz-1) && (i < siz-1); i++)
00037
00038 if (operator[](i+1) > operator[](i) + 1)
00039 pivot = i;
00040
00041
00042 operator[](pivot)++;
00043
00044
00045 for (int i = 0; i < pivot; i++)
00046 operator[](i) = i;
00047
00048
00049 if (operator[](siz-1) == numElements)
00050 endCondition = true;
00051
00052 return not endCondition;
00053 }
00054
00055 std::ostream& operator << ( std::ostream &os, const QVCombinationIterator &combination)
00056 {
00057 os << "Combination(" << combination.getSubsetsSize() << " elements over " << combination.getSetCardinallity() << "):\t";
00058
00059 for (int j = 0; j < combination[0]; j++)
00060 os << " " << j << " ";
00061 os << " [" << combination[0] << "]";
00062
00063 for (int i = 1; i < combination.getSubsetsSize(); i++)
00064 {
00065 for (int j = combination[i-1]+1; j < combination[i]; j++)
00066 os << " " << j << " ";
00067 os << " [" << combination[i] << "]";
00068 }
00069
00070 for (int j = combination[combination.getSubsetsSize()-1]; j < combination.getSetCardinallity()-1; j++)
00071 os << " " << (j+1) << " ";
00072
00073 os << std::endl;
00074
00075 return os;
00076 }