File: Permutation.hh

package info (click to toggle)
topcom 0.17.8%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 78,572 kB
  • sloc: cpp: 16,640; sh: 975; makefile: 345; ansic: 40
file content (94 lines) | stat: -rw-r--r-- 2,679 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
////////////////////////////////////////////////////////////////////////////////
// 
// Permutation.hh 
//
//    produced: 13/03/98 jr
// last change: 13/03/98 jr
//
////////////////////////////////////////////////////////////////////////////////
#ifndef PERMUTATION_HH
#define PERMUTATION_HH

#include <assert.h>

#include "PlainArray.hh"
#include "IntegerSet.hh"

#include "CommandlineOptions.hh"


typedef PlainArray<parameter_type> permutation_data;

class Permutation : public permutation_data {
private:
  parameter_type _n;
  parameter_type _k;
public:
  // constructors:
  inline Permutation();
  inline Permutation(const Permutation&);
  inline Permutation(const IntegerSet&);
  inline Permutation(const parameter_type, const parameter_type);
  inline Permutation(const parameter_type, const parameter_type, const IntegerSet&);
  // destructor:
  inline ~Permutation();
  // accessors:
  inline const parameter_type n() const;
  inline const parameter_type k() const;
  // functions:
  Permutation& append(const parameter_type);
  Permutation& append(const Permutation&);
  const int sign() const;
  const int sign(const parameter_type) const;
  const int sort();
  Permutation complement() const;
  Permutation deletion(const parameter_type m) const;
  Permutation reverse() const;
  bool lexnext();
  // stream output/input:
  friend std::ostream& operator<<(std::ostream& ost, const Permutation& p);
  friend std::istream& operator>>(std::istream& ist, Permutation& p);
};

// constructors:
inline Permutation::Permutation() : permutation_data(), _n(0), _k(0) {}
inline Permutation::Permutation(const Permutation& perm) : 
  permutation_data(perm), _n(perm._n), _k(perm._k) {}
inline Permutation::Permutation(const IntegerSet& s) : 
  permutation_data(), _n(0), _k(0) {
  for (IntegerSet::iterator iter = s.begin(); iter != s.end(); ++iter) {
    append(*iter);
  }
}
inline Permutation::Permutation(const parameter_type n, const parameter_type k) : 
  permutation_data(k), _n(n), _k(k) {
#ifdef INDEX_CHECK
  assert(_n > _k);
#endif
  for (parameter_type i = 0; i < _k; ++i) {
    (*this)[i] = i;
  }
}
inline Permutation::Permutation(const parameter_type n, 
				const parameter_type k, 
				const IntegerSet& s) : 
  permutation_data(k), _n(n), _k(k) {
  parameter_type i(0);
  for (IntegerSet::iterator iter = s.begin(); iter != s.end(); ++iter) {
    assert(*iter <= _n);
    assert(i < k);
    (*this)[i] = *iter;
    ++i;
  }
}

// destructor:
inline Permutation::~Permutation() {}

// accessors:
inline const parameter_type Permutation::n() const { return _n; }
inline const parameter_type Permutation::k() const { return _k; }

#endif

// eof Permutation.hh