1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Permutation.hh
4 //
5 // produced: 13/03/98 jr
6 // last change: 13/03/98 jr
7 //
8 ////////////////////////////////////////////////////////////////////////////////
9 #ifndef PERMUTATION_HH
10 #define PERMUTATION_HH
11
12 #include <assert.h>
13
14 #include "PlainArray.hh"
15 #include "IntegerSet.hh"
16
17 #include "CommandlineOptions.hh"
18
19
20 typedef PlainArray<parameter_type> permutation_data;
21
22 class Permutation : public permutation_data {
23 private:
24 parameter_type _n;
25 parameter_type _k;
26 public:
27 // constructors:
28 inline Permutation();
29 inline Permutation(const Permutation&);
30 inline Permutation(const IntegerSet&);
31 inline Permutation(const parameter_type, const parameter_type);
32 inline Permutation(const parameter_type, const parameter_type, const IntegerSet&);
33 // destructor:
34 inline ~Permutation();
35 // accessors:
36 inline const parameter_type n() const;
37 inline const parameter_type k() const;
38 // functions:
39 Permutation& append(const parameter_type);
40 Permutation& append(const Permutation&);
41 const int sign() const;
42 const int sign(const parameter_type) const;
43 const int sort();
44 Permutation complement() const;
45 Permutation deletion(const parameter_type m) const;
46 Permutation reverse() const;
47 bool lexnext();
48 // stream output/input:
49 friend std::ostream& operator<<(std::ostream& ost, const Permutation& p);
50 friend std::istream& operator>>(std::istream& ist, Permutation& p);
51 };
52
53 // constructors:
Permutation()54 inline Permutation::Permutation() : permutation_data(), _n(0), _k(0) {}
Permutation(const Permutation & perm)55 inline Permutation::Permutation(const Permutation& perm) :
56 permutation_data(perm), _n(perm._n), _k(perm._k) {}
Permutation(const IntegerSet & s)57 inline Permutation::Permutation(const IntegerSet& s) :
58 permutation_data(), _n(0), _k(0) {
59 for (IntegerSet::iterator iter = s.begin(); iter != s.end(); ++iter) {
60 append(*iter);
61 }
62 }
Permutation(const parameter_type n,const parameter_type k)63 inline Permutation::Permutation(const parameter_type n, const parameter_type k) :
64 permutation_data(k), _n(n), _k(k) {
65 #ifdef INDEX_CHECK
66 assert(_n > _k);
67 #endif
68 for (parameter_type i = 0; i < _k; ++i) {
69 (*this)[i] = i;
70 }
71 }
Permutation(const parameter_type n,const parameter_type k,const IntegerSet & s)72 inline Permutation::Permutation(const parameter_type n,
73 const parameter_type k,
74 const IntegerSet& s) :
75 permutation_data(k), _n(n), _k(k) {
76 parameter_type i(0);
77 for (IntegerSet::iterator iter = s.begin(); iter != s.end(); ++iter) {
78 assert(*iter <= _n);
79 assert(i < k);
80 (*this)[i] = *iter;
81 ++i;
82 }
83 }
84
85 // destructor:
~Permutation()86 inline Permutation::~Permutation() {}
87
88 // accessors:
n() const89 inline const parameter_type Permutation::n() const { return _n; }
k() const90 inline const parameter_type Permutation::k() const { return _k; }
91
92 #endif
93
94 // eof Permutation.hh
95