Honeycomb
0.1
Component-Model Framework
|
Generate all permutations of a list. A functor can be specified for fast culling of entire subtrees of undesired permutations. More...
#include <Permute.h>
Classes | |
class | Iter |
Iter for permutations of a list. More... | |
Static Public Member Functions | |
template<class T > | |
static Range_< Iter< T >, Iter< T > > | range (const vector< T > &list, const typename Iter< T >::Func &func=nullptr) |
Create a permutation range. More... | |
Generate all permutations of a list. A functor can be specified for fast culling of entire subtrees of undesired permutations.
The permuations are in lexicographic order. ie. {1,2,3} , {1,3,2} , {2,1,3} , {2,3,1} , {3,1,2} , {3,2,1}
The current permutation list can be accessed with the dereference/pointer operators.
If a functor is provided then undesired subtrees can be culled. For example, skip all permutations that start with {0,1}:
Permute::range(list, [](const vector<const Real*>& perm) { return !(perm.size() == 2 && *perm[0] == 0 && *perm[1] == 1); });
When an iter is stepped (++), its functor will be called before traversing each permutation subtree.
For example, perm
will first contain {1}, if the functor returns true then the next test is {1,2}, then finally {1,2,3}.
When the functor returns true for a full permutation (ex. {1,2,3}), then the iter step is complete.
Copies of the iter share its permutation state, so a change to one iter affects all others.
Algorithm from: "Lexicographic Permutations with Restricted Prefixes" from The Art of Computer Programming, Vol 4, Section 7.2.1.2
|
inlinestatic |
Create a permutation range.