48 size_type nb_permutations() {
return permutation::nb_permutations(size()); }
50 {
size_type f=1;
for (; n>1; --n) f *= n;
return f; }
54 { (*this)[i] = dim_type(i); remaining *= (i+1); }
59 for (
size_type i=0; i < size(); ++i) pinv[(*
this)[i]] = dim_type(i);
63 bool finished()
const {
return remaining == 0; }
66 template <
typename CONT1,
typename CONT2 >
void apply_to(
const CONT1& src, CONT2& dest)
67 {
for (
size_type i=0; i < size(); ++i) dest[i] = src[(*
this)[i]]; }
72 std::swap((*
this)[n-1], (*
this)[r % n]);
77 inline size_type permutation::rank()
const {
83 std::swap(p[n-1], p[pinv[n-1]]);
84 std::swap(pinv[s],pinv[n-1]);
89 inline const permutation &permutation::operator ++() {
90 if (--remaining == 0)
return (*
this);
92 while ((*
this)[i] > (*
this)[i+1]) i--;
93 while ((*
this)[i] > (*
this)[j]) j--;
94 std::swap((*
this)[i], (*
this)[j]);
95 for (
size_type r = size()-1, s=i+1; r>s; --r, ++s) std::swap((*
this)[r],(*
this)[s]);
generation of permutations, and ranking/unranking of these.
size_t size_type
used as the common size type in the library
defines and typedefs for namespace bgeot