finitediff
MelementaryPermutation.h
Go to the documentation of this file.
1 /*
2 Copyright 2017 Laurent Claessens
3 contact : laurent@claessens-donadello.eu
4 
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef __MELEMENTARYPERMUTATION_H_095019_
20 #define __MELEMENTARYPERMUTATION_H_095019_
21 
22 #include "../Utilities.h"
23 #include "MgenericPermutation.h"
24 
25 template <unsigned int tp_size>
27 
33 template <unsigned int tp_size>
35 {
36  template <unsigned int s>
37  friend std::ostream& operator<<(std::ostream&, MelementaryPermutation<s>);
38 
39  private:
41  const unsigned int data_elA;
43  const unsigned int data_elB;
44 
45  public :
52  MelementaryPermutation(const unsigned int A,const unsigned int B);
53 
57  unsigned int getA() const;
61  unsigned int getB() const;
62 
66  unsigned int image(const unsigned int k) const override;
67 
68 };
69 
70 // GETTER/SETTER METHODS ---------------------------------
71 
72 template <unsigned int tp_size>
74 {
75  return data_elA;
76 }
77 
78 template <unsigned int tp_size>
80 {
81  return data_elB;
82 }
83 
84 // OPERATORS ---------------------------------
85 
86 template <unsigned int s>
87 std::ostream& operator<<(std::ostream& stream, MelementaryPermutation<s> perm)
88 {
89  stream<<perm.getA()<<" <--> "<<perm.getB();
90  return stream;
91 }
92 
93 // ACTION ON THE INTEGERS ---------------------------------
94 
95 template <unsigned int tp_size>
96 MelementaryPermutation<tp_size>::MelementaryPermutation(const unsigned int A,const unsigned int B) :
97  data_elA(A),
98  data_elB(B)
99 {
100  if (getA() > tp_size or getB() > tp_size)
101  {
103  }
104 }
105 
106 template <unsigned int tp_size>
107 unsigned int MelementaryPermutation<tp_size>::image(const unsigned int k) const
108 {
109  if (k>tp_size)
110  {
111  throw PermutationIdexoutOfRangeException(k,tp_size);
112  }
113  if (k==getA())
114  {
115  return getB();
116  }
117  if (k==getB())
118  {
119  return getA();
120  }
121  return k;
122 }
123 
124 #endif
125 
126 
const unsigned int data_elA
Definition: MelementaryPermutation.h:41
const unsigned int data_elB
Definition: MelementaryPermutation.h:43
A permutation is a bijection of a finite subset of N.
Definition: MgenericPermutation.h:48
unsigned int image(const unsigned int k) const override
return by value the image of &#39;k&#39; by the permutation.
Definition: MelementaryPermutation.h:107
unsigned int getA() const
Return the first of the two elements that are permuted.
Definition: MelementaryPermutation.h:73
Definition: MelementaryPermutation.h:34
unsigned int getB() const
Return the second of the two elements that are permuted.
Definition: MelementaryPermutation.h:79
Definition: SNexceptions.cpp:177
This class represents a permutation (not a matrix).
Definition: MelementaryPermutation.h:26
MelementaryPermutation(const unsigned int A, const unsigned int B)
Definition: MelementaryPermutation.h:96