Enumerator for k-subsets of a given type. More...
#include <ogdf/basic/SubsetEnumerator.h>
Public Member Functions | |
| template<typename ContainerType > | |
| SubsetEnumerator (const ContainerType &set) | |
| Constructor. | |
| void | array (Array< T > &array) const |
| Obtains an array of the subset members. | |
| void | begin () |
| Initializes the SubsetEnumerator to enumerate all subsets. | |
| void | begin (int card) |
| Initializes the SubsetEnumerator to enumerate subsets of given cardinality. | |
| void | begin (int low, int high) |
| Initializes the SubsetEnumerator to enumerate subsets of cardinalities from low to high. | |
| void | forEachMember (std::function< void(const T &)> func) const |
Calls func for each member in the subset. | |
| void | forEachMemberAndNonmember (std::function< void(const T &)> funcIn, std::function< void(const T &)> funcNotIn) const |
Calls funcIn for each subset member and funcNotIn for each other element of the set. | |
| template<typename ContainerType > | |
| void | getSubsetAndComplement (ContainerType &subset, ContainerType &complement, std::function< void(ContainerType &, T)> func) const |
| Obtains a container of the subset members and a container of the other elements of the set. | |
| bool | hasMember (const T &element) const |
Checks in O(subset cardinality) whether element is a member of the subset. | |
| void | list (List< T > &subset) const |
| Obtains (appends) a list of the subset members. | |
| void | list (List< T > &subset, List< T > &complement) const |
| Obtains (appends) a list of the subset members and a list of the other elements of the set. | |
| void | next () |
| Obtains the next subset if possible. The result should be checked using the valid() method. | |
| int | numberOfMembersAndNonmembers () const |
| Returns the cardinality of the (super-)set. This is the maximum size that can be used for a subset. | |
| T | operator[] (int i) const |
| Gets a member of subset by index (starting from 0). | |
| void | print (std::ostream &os, string delim=" ") const |
Prints subset to output stream os using delimiter delim. | |
| int | size () const |
| Returns the cardinality of the subset. | |
| bool | testForAll (std::function< bool(const T &)> predicate) const |
Tests predicate for all subset members. | |
| bool | valid () const |
| Checks if the current subset is valid. If not, the subset is either not initialized or all subsets have already been enumerated. | |
Protected Member Functions | |
| void | initSubset (int card) |
Protected Attributes | |
| Array< int > | m_index |
| int | m_maxCard |
| ArrayBuffer< T > | m_subset |
| bool | m_valid |
Enumerator for k-subsets of a given type.
Please note that the internal data structures of SubsetEnumerator do not use references of the type T. Hence, T should either be a simple type or a pointer to a complex type (which is also only sane for Lists, too). Otherwise the data structure will slow down due to extensive implicit copying.
Definition at line 88 of file SubsetEnumerator.h.
|
inlineexplicit |
Constructor.
| set | The container of elements we want to enumerate subsets for. |
Definition at line 112 of file SubsetEnumerator.h.
|
inline |
Obtains an array of the subset members.
Definition at line 207 of file SubsetEnumerator.h.
|
inline |
Initializes the SubsetEnumerator to enumerate all subsets.
Definition at line 134 of file SubsetEnumerator.h.
|
inline |
Initializes the SubsetEnumerator to enumerate subsets of given cardinality.
Definition at line 131 of file SubsetEnumerator.h.
|
inline |
Initializes the SubsetEnumerator to enumerate subsets of cardinalities from low to high.
Definition at line 120 of file SubsetEnumerator.h.
|
inline |
Calls func for each member in the subset.
Definition at line 195 of file SubsetEnumerator.h.
|
inline |
Calls funcIn for each subset member and funcNotIn for each other element of the set.
Definition at line 215 of file SubsetEnumerator.h.
|
inline |
Obtains a container of the subset members and a container of the other elements of the set.
Definition at line 229 of file SubsetEnumerator.h.
|
inline |
Checks in O(subset cardinality) whether element is a member of the subset.
Definition at line 148 of file SubsetEnumerator.h.
|
inlineprotected |
Definition at line 95 of file SubsetEnumerator.h.
|
inline |
Obtains (appends) a list of the subset members.
Definition at line 202 of file SubsetEnumerator.h.
|
inline |
Obtains (appends) a list of the subset members and a list of the other elements of the set.
Definition at line 236 of file SubsetEnumerator.h.
|
inline |
Obtains the next subset if possible. The result should be checked using the valid() method.
Definition at line 165 of file SubsetEnumerator.h.
|
inline |
Returns the cardinality of the (super-)set. This is the maximum size that can be used for a subset.
Definition at line 141 of file SubsetEnumerator.h.
|
inline |
Gets a member of subset by index (starting from 0).
Definition at line 158 of file SubsetEnumerator.h.
|
inline |
Prints subset to output stream os using delimiter delim.
Definition at line 252 of file SubsetEnumerator.h.
|
inline |
Returns the cardinality of the subset.
Definition at line 137 of file SubsetEnumerator.h.
|
inline |
Tests predicate for all subset members.
Definition at line 242 of file SubsetEnumerator.h.
|
inline |
Checks if the current subset is valid. If not, the subset is either not initialized or all subsets have already been enumerated.
Definition at line 145 of file SubsetEnumerator.h.
|
protected |
Definition at line 93 of file SubsetEnumerator.h.
|
protected |
Definition at line 91 of file SubsetEnumerator.h.
|
protected |
Definition at line 92 of file SubsetEnumerator.h.
|
protected |
Definition at line 90 of file SubsetEnumerator.h.