1 #ifndef VIGRA_PERMUTATION_HXX
2 #define VIGRA_PERMUTATION_HXX
6 #include "array_vector.hxx"
7 #include "tinyvector.hxx"
11 template <
unsigned int N>
12 class Permutation :
public TinyVector<unsigned int, N>
15 typedef TinyVector<unsigned int, N> base_type;
16 typedef typename base_type::size_type size_type;
17 typedef typename base_type::value_type value_type;
18 typedef typename base_type::iterator iterator;
19 typedef typename base_type::const_iterator const_iterator;
20 typedef typename base_type::reference reference;
21 typedef typename base_type::const_reference const_reference;
22 typedef typename base_type::pointer pointer;
23 typedef typename base_type::const_pointer const_pointer;
24 typedef int integral_type;
26 Permutation() : base_type() {}
28 Permutation(
const Permutation<N-1> & other,
const size_type index)
33 "Permutation::Permutation(): Invalid index");
34 for (size_type n = 0; n < N; n++)
38 (*this)[n] = other[n];
46 (*this)[n] = other[n-1];
49 if ((N - 1 - index) % 2 == 0)
51 sign_ = (other.sign() == 1);
55 sign_ = (other.sign() == -1);
59 integral_type
sign()
const
77 class Permutation<1> :
public TinyVector<unsigned int, 1>
80 typedef TinyVector<unsigned int, 1> base_type;
81 typedef base_type::size_type size_type;
82 typedef base_type::value_type value_type;
83 typedef base_type::iterator iterator;
84 typedef base_type::const_iterator const_iterator;
85 typedef base_type::reference reference;
86 typedef base_type::const_reference const_reference;
87 typedef base_type::pointer pointer;
88 typedef base_type::const_pointer const_pointer;
89 typedef int integral_type;
91 Permutation() : base_type()
97 integral_type
sign()
const
113 template <
unsigned int N>
114 class PlainChangesPermutations :
public ArrayVector<Permutation<N> >
117 typedef ArrayVector<Permutation<N> > base_type;
118 typedef typename base_type::size_type size_type;
119 typedef typename base_type::value_type value_type;
120 typedef typename base_type::iterator iterator;
121 typedef typename base_type::const_iterator const_iterator;
122 typedef typename base_type::reference reference;
123 typedef typename base_type::const_reference const_reference;
124 typedef typename base_type::pointer pointer;
125 typedef typename base_type::const_pointer const_pointer;
127 PlainChangesPermutations() : base_type()
129 PlainChangesPermutations<N-1> permutations;
130 for (
auto permutation : permutations)
132 if (permutation.sign() == -1)
134 for (
unsigned int n = 0; n < N; n++)
136 this->push_back(Permutation<N>(permutation, n));
141 for (
unsigned int n = N; n > 0; n--)
143 this->push_back(Permutation<N>(permutation, n - 1));
151 class PlainChangesPermutations<1> :
public ArrayVector<Permutation<1> >
154 typedef ArrayVector<Permutation<1> > base_type;
155 typedef base_type::size_type size_type;
156 typedef base_type::value_type value_type;
157 typedef base_type::iterator iterator;
158 typedef base_type::const_iterator const_iterator;
159 typedef base_type::reference reference;
160 typedef base_type::const_reference const_reference;
161 typedef base_type::pointer pointer;
162 typedef base_type::const_pointer const_pointer;
164 PlainChangesPermutations() : base_type()
166 this->push_back(Permutation<1>());
T sign(T t)
The sign function.
Definition: mathutil.hxx:591