MINT2
Permutation.h
Go to the documentation of this file.
1 #ifndef PERMUTATION_HH
2 #define PERMUTATION_HH
3 // author: Jonas Rademacker (Jonas.Rademacker@bristol.ac.uk)
4 // status: Mon 9 Feb 2009 19:18:13 GMT
5 
6 //#include <vector>
7 #include <iostream>
8 #include "Mint/PolymorphVector.h"
9 
10 /*
11  naming: is the 'normal' ordering, i.e. 1, 2, 3, 4,...
12  whyle y is what it's been mapped to, e.g.
13  x = 1, 2, 3, 4, 5
14  y = 2, 1, 3, 4, 5
15 
16 */
17 
19  protected:
20  // begin data members
21 
22  std::vector<int> _v;
23  int _sign;
24 
25  // end data members
26 
28 
29 
30  static int dummy;
31  int& y_of_x(int i);
32  const int& y_of_x(int i) const;
33 
34  public:
35 
36  static const Permutation& unity();
37 
38  void swap(int x1, int x2, int sgn=1);
39  void set(const std::vector<int>& v, int sgn=1);
40  void set(int a);
41  void set(int a, int b);
42  void set(int a, int b, int c);
43  void set(int a, int b, int c, int d);
44  void set(int a, int b, int c, int d, int e);
45  void setSign(int s);
46 
47  void reset(int n);
48  void makeUnity();
49  bool isUnity() const;
50 
51  Permutation getInverse() const;
52 
53  unsigned int size() const{ return _v.size();}
54 
55  Permutation(int n=1) : _v(n), _sign(1){reset(n);};
56  Permutation(const Permutation& other)
57  : _v(other._v), _sign(other._sign)
58  {}
59 
60  int sign() const{return _sign;}
61 
62  int operator[] (int i) const{
63  return y_of_x(i);
64  }
65 
66  int& operator[] (int i){
67  return y_of_x(i);
68  }
69 
70  std::vector<int>& mapValues(const std::vector<int>& in
71  , std::vector<int>& out) const{
72  // same as mapValues below, except no new vector needs allocating
73  // good when time is precious...
74  if(this->isUnity()){
75  out = in;
76  return out;
77  }
78 
79  out.resize(in.size());
80  for(unsigned int i=0; i < in.size(); i++){
81  out[i] = y_of_x(in[i]);
82  }
83  return out;
84  }
85  std::vector<int> mapValues(const std::vector<int>& in) const{
86  std::vector<int> out(in.size());
87  return mapValues(in, out);
88  }
89 
90  template<typename T>
91  std::vector<T>& mapOrder(const std::vector<T>& in
92  , std::vector<T>& out) const{
93  out.resize(in.size());
94  unsigned int to = in.size();
95  if(in.size() > this->size()){
96  to = this->size();
97  for(unsigned int i = this->size(); i < in.size(); i++) out[i] = in[i];
98  }
99 
100  for(unsigned int i=0; i < to; i++){
101  out[y_of_x(i)] = in[i];
102  }
103  return out;
104  }
105 
106  template<typename T>
107  std::vector<T>& mapOrder(const MINT::PolymorphVector<T>& pv
108  , std::vector<T>& out) const{
109  return mapOrder(pv.theVector(), out);
110  }
111  template<typename T>
113  , MINT::PolymorphVector<T>& out) const{
114  mapOrder(pv.theVector(), out.theVector());
115  return out;
116  }
117 
118  template<typename T>
119  std::vector<T> mapOrder(const std::vector<T>& in) const{
120  std::vector<T> out(in.size());
121  return mapOrder(in, out);
122  }
123  template<typename T>
125  MINT::PolymorphVector<T> out(in.size());
126  return mapOrder(in, out);
127  }
128 
129  int nPermutations() const;
130 
131  void print(std::ostream& os = std::cout) const;
132 
133  Permutation operator*(const Permutation& rhs) const;
134  Permutation operator/(const Permutation& rhs) const;
135 
136  bool operator<(const Permutation& rhs)const;
137  bool operator==(const Permutation& rhs)const;
138  bool operator<=(const Permutation& rhs)const;
139  bool operator>(const Permutation& rhs)const;
140  bool operator>=(const Permutation& rhs)const;
141 };
142 
143 std::ostream& operator<<(std::ostream& os, const Permutation& p);
144 
145 #endif
void reset(int n)
Definition: Permutation.cpp:38
int nPermutations() const
std::vector< int > mapValues(const std::vector< int > &in) const
Definition: Permutation.h:85
Permutation(const Permutation &other)
Definition: Permutation.h:56
void setSign(int s)
Definition: Permutation.cpp:81
std::vector< int > _v
Definition: Permutation.h:22
MINT::PolymorphVector< T > mapOrder(const MINT::PolymorphVector< T > &in) const
Definition: Permutation.h:124
int sign() const
Definition: Permutation.h:60
static const double s
void swap(int x1, int x2, int sgn=1)
Definition: Permutation.cpp:54
std::ostream & operator<<(std::ostream &os, const Permutation &p)
void print(std::ostream &os=std::cout) const
bool operator<=(const Permutation &rhs) const
MINT::PolymorphVector< T > & mapOrder(const MINT::PolymorphVector< T > &pv, MINT::PolymorphVector< T > &out) const
Definition: Permutation.h:112
Permutation operator *(const Permutation &rhs) const
Permutation(int n=1)
Definition: Permutation.h:55
int & y_of_x(int i)
Definition: Permutation.cpp:19
void makeUnity()
Definition: Permutation.cpp:42
bool isUnity() const
Definition: Permutation.cpp:47
std::vector< T > & mapOrder(const MINT::PolymorphVector< T > &pv, std::vector< T > &out) const
Definition: Permutation.h:107
bool operator>=(const Permutation &rhs) const
static int dummy
Definition: Permutation.h:30
static const Permutation & unity()
Definition: Permutation.cpp:10
unsigned int size() const
int operator[](int i) const
Definition: Permutation.h:62
unsigned int size() const
Definition: Permutation.h:53
bool operator==(const Permutation &rhs) const
std::vector< T > & theVector()
bool operator<(const Permutation &rhs) const
void set(const std::vector< int > &v, int sgn=1)
Definition: Permutation.cpp:61
bool operator>(const Permutation &rhs) const
std::vector< T > mapOrder(const std::vector< T > &in) const
Definition: Permutation.h:119
std::vector< int > & mapValues(const std::vector< int > &in, std::vector< int > &out) const
Definition: Permutation.h:70
std::vector< T > & mapOrder(const std::vector< T > &in, std::vector< T > &out) const
Definition: Permutation.h:91
static Permutation * __unit
Definition: Permutation.h:27
Permutation operator/(const Permutation &rhs) const
Permutation getInverse() const
Definition: Permutation.cpp:84