|
template<typename ContainerType > |
| SubsetEnumerator (const ContainerType &set) |
| Constructor. More...
|
|
void | array (Array< T > &array) const |
| Obtains an array of the subset members. More...
|
|
void | begin () |
| Initializes the SubsetEnumerator to enumerate all subsets. More...
|
|
void | begin (int card) |
| Initializes the SubsetEnumerator to enumerate subsets of given cardinality. More...
|
|
void | begin (int low, int high) |
| Initializes the SubsetEnumerator to enumerate subsets of cardinalities from low to high. More...
|
|
void | forEachMember (std::function< void(const T &)> func) const |
| Calls func for each member in the subset. More...
|
|
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. More...
|
|
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. More...
|
|
bool | hasMember (const T &element) const |
| Checks in O(subset cardinality) whether element is a member of the subset. More...
|
|
void | list (List< T > &subset) const |
| Obtains (appends) a list of the subset members. More...
|
|
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. More...
|
|
void | next () |
| Obtains the next subset if possible. The result should be checked using the valid() method. More...
|
|
int | numberOfMembersAndNonmembers () const |
| Returns the cardinality of the (super-)set. This is the maximum size that can be used for a subset. More...
|
|
T | operator[] (int i) const |
| Gets a member of subset by index (starting from 0). More...
|
|
void | print (std::ostream &os, string delim=" ") const |
| Prints subset to output stream os using delimiter delim . More...
|
|
int | size () const |
| Returns the cardinality of the subset. More...
|
|
bool | testForAll (std::function< bool(const T &)> predicate) const |
| Tests predicate for all subset members. More...
|
|
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. More...
|
|
template<typename T>
class ogdf::SubsetEnumerator< T >
Enumerator for k-subsets of a given type.
Usage examples
-
Enumerate all subsets of edges with cardinality 3:
List<edge> edges;
do_something_eg_fill_edges();
SubsetEnumerator<edge> subset(edges);
for (subset.begin(3); subset.valid(); subset.next()) {
do_something_with(subset[0], subset[1], subset[2]);
}
-
Enumerate all subsets of edges:
SubsetEnumerator<edge> subset(edges);
for (subset.begin(); subset.valid(); subset.next()) {
for (int i = 0; i < subset.size(); ++i) {
do_something_with(subset[i]);
}
do_stuff();
}
-
Do something with member lists and complement lists of all 2-, 3-, and 4-element subsets
SubsetEnumerator<edge> subset(edges);
for (subset.begin(2, 4); subset.valid(); subset.next()) {
List<edge> list1, list2;
subset.list(list1, list2);
do_something_with(list1);
do_another_things_with(list2);
}
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 97 of file SubsetEnumerator.h.