|
ADS
Algorithms and Data Structures
|
The generation of the basic combinatorial objects of Knuth (section 7.2.1 of The Art of Computer Programming), beyond the book [see Enumeration.h for the enumerations by backtrack of chapter 16]: each function calls visit() on every object, in a given order, and returns their number; a visit that returns true stops the generation, and one that returns void never does (as in FastGeneration.h). More...
#include "ADS/Contract.h"#include <algorithm>#include <cstddef>#include <string>#include <type_traits>#include <utility>#include <vector>#include "ADS/combinatorial/impl/Generation.tpp"Go to the source code of this file.
Namespaces | |
| namespace | ADS |
Typedefs | |
| using | ADS::Tuple = std::vector< int > |
| a tuple, a permutation, a string | |
Functions | |
| template<class F> | |
| long | ADS::mixedRadix (const std::vector< int > &m, F &&visit) |
| the tuples \( ( a_0 , \ldots , a_{n-1} ) \) with \( 0 \le a_j < m_j \), in lexicographic order, \( O( 1 ) \) amortized per tuple after \( O( n ) \) | |
| template<class F> | |
| long | ADS::grayTuples (const std::vector< int > &m, F &&visit) |
| the tuples with \( 0 \le a_j < m_j \) in the reflected Gray order, loopless | |
| template<class F> | |
| long | ADS::permutationsLex (Tuple a, F &&visit) |
| the permutations of the multiset \( a \), in lexicographic order from \( a \) sorted | |
| template<class F> | |
| long | ADS::plainChanges (int n, F &&visit) |
| the permutations of \( 0 , \ldots , n - 1 \) by swaps of adjacent items, \( O( 1 ) \) amortized per permutation, the same vector visited each time | |
| template<class F> | |
| long | ADS::heapPermutations (int n, F &&visit) |
| the permutations of \( 0 , \ldots , n - 1 \) by Heap's method, one swap each | |
| template<class F> | |
| long | ADS::combinationsLex (int n, int t, F &&visit) |
| the \( t \)-combinations of \( 0 , \ldots , n - 1 \) as increasing tuples, in lexicographic order | |
| template<class F> | |
| long | ADS::revolvingDoor (int n, int t, F &&visit) |
| the \( t \)-combinations of \( 0 , \ldots , n - 1 \) in the revolving-door order | |
| template<class F> | |
| long | ADS::integerPartitions (int n, F &&visit) |
| the partitions of \( n \), their parts nonincreasing, in reverse lexicographic order, \( O( 1 ) \) amortized per partition | |
| template<class F> | |
| long | ADS::setPartitions (int n, F &&visit) |
| the restricted growth strings of the partitions of a set of \( n \) items, in lexicographic order, \( O( 1 ) \) amortized per partition | |
| template<class F> | |
| long | ADS::nestedParentheses (int n, F &&visit) |
| the strings of \( n \) pairs of balanced parentheses, in lexicographic order | |
The generation of the basic combinatorial objects of Knuth (section 7.2.1 of The Art of Computer Programming), beyond the book [see Enumeration.h for the enumerations by backtrack of chapter 16]: each function calls visit() on every object, in a given order, and returns their number; a visit that returns true stops the generation, and one that returns void never does (as in FastGeneration.h).
The counts are \( \prod_j m_j \), the multinomial \( n! / \prod_v m_v! \) of the multiplicities, \( n! \), \( \binom{n}{t} \), \( p( n ) \), the Bell number \( \varpi_n \) and the Catalan number \( C_n \), and the tests check them. The contracts [see Contract.h]: the radices are positive, \( 0 \le t \le n \), \( n \ge 0 \). The functions are defined in Generation.tpp.