|
| 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.
|
| |
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:
do_something_eg_fill_edges();
for (subset.begin(3); subset.valid(); subset.next()) {
do_something_with(subset[0], subset[1], subset[2]);
}
Doubly linked lists (maintaining the length of the list).
Enumerator for k-subsets of a given type.
-
Enumerate all subsets of 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
for (subset.begin(2, 4); subset.valid(); subset.next()) {
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.