98 if (card >= 0 && card <= m_subset.
size()) {
100 for (
int i = 0; i < card; ++i) {
113 , m_subset(set.
size())
116 for(
const T &x : m_set) {
143 return m_index.
size();
155 for (
int i = 0; i < m_index.
size(); ++i) {
156 if (element == m_subset[m_index[i]]) {
168 return m_subset[m_index[i]];
175 const int t = m_index.
size();
184 const int n = m_subset.
size();
186 for (i = t - 1; m_index[i] == i + n - t; --i) {
196 for (++m_index[i]; i < t - 1; ++i) {
197 m_index[i + 1] = m_index[i] + 1;
205 for (
int i = 0; i < m_index.
size(); ++i) {
206 list.
pushBack(m_subset[m_index[i]]);
214 for (
int i = 0; i < m_index.
size(); ++i) {
215 array[i] = m_subset[m_index[i]];
223 for (
int i = 0; i < m_subset.
size(); ++i) {
224 if (j < m_index.
size() && m_index[j] == i) {
240 if (subset.
size() > 0) {
243 for (
int i = 1; i < subset.
size(); ++i) {
244 os << delim << subset[i];
250 ostream &operator<<(ostream &os, const SubsetEnumerator<T> &subset)
iterator pushBack(const E &x)
Adds element x at the end of the list.
void init()
Reinitializes the array to an array with empty index set.
void begin(int card)
Initialize the SubsetEnumerator to enumerate subsets of given cardinality.
bool valid() const
Is the current subset valid? If not, all subsets have already been enumerated.
void begin()
Initialize the SubsetEnumerator to enumerate all subsets.
void list(List< T > &list, List< T > &complement) const
Obtain (append) a list of the elements in the subset and a list of the other elements of the set...
void begin(int low, int high)
Initialize the SubsetEnumerator to enumerate subsets of cardinalities from low to high...
INDEX size() const
Returns the size (number of elements) of the array.
Enumerator for k-subsets of a given type.
void initSubset(int card)
bool hasMember(const T &element) const
Check in O(subset cardinality) whether the argument is a member of the subset.
SubsetEnumerator(const List< T > &set)
Constructor.
void list(List< T > &list) const
Obtain (append) a list of the elements in the subset.
void next()
Obtain the next subset if possible. The result should be checked using the valid() method...
int size() const
Returns the number of elements in the list.
int size() const
Return the cardinality of the subset.
The namespace for all OGDF objects.
T operator[](int i) const
Get element of subset by index (starting from 0).
void print(ostream &os, const Array< E, INDEX > &a, char delim=' ')
Prints array a to output stream os using delimiter delim.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Declaration of doubly linked lists and iterators.
void array(Array< T > &array) const
Obtain an array of the elements in the subset.