Lolly 1.4.27
Loading...
Searching...
No Matches
ntuple.hpp
Go to the documentation of this file.
1
2/******************************************************************************
3 * MODULE : ntuple.hpp
4 * DESCRIPTION: Pairs, triples and quartets
5 * COPYRIGHT : (C) 2007 Joris van der Hoeven
6 *******************************************************************************
7 * This software falls under the GNU general public license version 3 or later.
8 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
9 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
10 ******************************************************************************/
11
12#ifndef NTUPLE_H
13#define NTUPLE_H
14#include "basic.hpp"
15
16template <class T1, class T2> class pair {
17public:
18 T1 x1;
19 T2 x2;
20 inline pair (const pair& p) : x1 (p.x1), x2 (p.x2) {}
21 inline pair (const T1& y1, const T2& y2) : x1 (y1), x2 (y2) {}
22 inline pair& operator= (const pair& p) {
23 x1= p.x1;
24 x2= p.x2;
25 return *this;
26 }
27 inline bool operator== (const pair& p) { return x1 == p.x1 && x2 == p.x2; }
28 inline bool operator!= (const pair& p) { return x1 != p.x1 || x2 != p.x2; }
29};
30
31template <class T1, class T2>
32int
33hash (const pair<T1, T2>& p) {
34 int h1= hash (p.x1);
35 return (h1 << 11) ^ (h1 >> 21) ^ hash (p.x2);
36}
37
38template <class T1, class T2>
40operator<< (tm_ostream& out, const pair<T1, T2>& p) {
41 return out << "[ " << p.x1 << ", " << p.x2 << " ]";
42}
43
44template <class T1, class T2, class T3> class triple {
45public:
46 T1 x1;
47 T2 x2;
48 T3 x3;
49 inline triple (const triple& t) : x1 (t.x1), x2 (t.x2), x3 (t.x3) {}
50 inline triple (const T1& y1, const T2& y2, const T3& y3)
51 : x1 (y1), x2 (y2), x3 (y3) {}
52 inline triple& operator= (const triple& t) {
53 x1= t.x1;
54 x2= t.x2;
55 x3= t.x3;
56 return *this;
57 }
58 inline bool operator== (const triple& t) {
59 return x1 == t.x1 && x2 == t.x2 && x3 == t.x3;
60 }
61 inline bool operator!= (const triple& t) {
62 return x1 != t.x1 || x2 != t.x2 || x3 != t.x3;
63 }
64};
65
66template <class T1, class T2, class T3>
67int
69 int h= hash (t.x1);
70 h = (h << 11) ^ (h >> 21) ^ hash (t.x2);
71 return (h << 11) ^ (h >> 21) ^ hash (t.x3);
72}
73
74template <class T1, class T2, class T3>
77 return out << "[ " << t.x1 << ", " << t.x2 << ", " << t.x3 << " ]";
78}
79
80template <class T1, class T2, class T3, class T4> class quartet {
81public:
82 T1 x1;
83 T2 x2;
84 T3 x3;
85 T4 x4;
86 inline quartet (const quartet& q)
87 : x1 (q.x1), x2 (q.x2), x3 (q.x3), x4 (q.x4) {}
88 inline quartet (const T1& y1, const T2& y2, const T3& y3, const T4& y4)
89 : x1 (y1), x2 (y2), x3 (y3), x4 (y4) {}
90 inline quartet& operator= (const quartet& q) {
91 x1= q.x1;
92 x2= q.x2;
93 x3= q.x3;
94 x4= q.x4;
95 return *this;
96 }
97 inline bool operator== (const quartet& q) {
98 return x1 == q.x1 && x2 == q.x2 && x3 == q.x3 && x4 == q.x4;
99 }
100 inline bool operator!= (const quartet& q) {
101 return x1 != q.x1 || x2 != q.x2 || x3 != q.x3 || x4 != q.x4;
102 }
103};
104
105template <class T1, class T2, class T3, class T4>
106int
108 int h= hash (q.x1);
109 h = (h << 11) ^ (h >> 21) ^ hash (q.x2);
110 h = (h << 11) ^ (h >> 21) ^ hash (q.x3);
111 return (h << 11) ^ (h >> 21) ^ hash (q.x4);
112}
113
114template <class T1, class T2, class T3, class T4>
117 return out << "[ " << q.x1 << ", " << q.x2 << ", " << q.x3 << ", " << q.x4
118 << " ]";
119}
120
121template <class T1, class T2, class T3, class T4, class T5> class quintuple {
122public:
123 T1 x1;
124 T2 x2;
125 T3 x3;
126 T4 x4;
127 T5 x5;
128 inline quintuple (const quintuple& q)
129 : x1 (q.x1), x2 (q.x2), x3 (q.x3), x4 (q.x4), x5 (q.x5) {}
130 inline quintuple (const T1& y1, const T2& y2, const T3& y3, const T4& y4,
131 const T5& y5)
132 : x1 (y1), x2 (y2), x3 (y3), x4 (y4), x5 (y5) {}
133 inline quintuple& operator= (const quintuple& q) {
134 x1= q.x1;
135 x2= q.x2;
136 x3= q.x3;
137 x4= q.x4;
138 x5= q.x5;
139 return *this;
140 }
141 inline bool operator== (const quintuple& q) {
142 return x1 == q.x1 && x2 == q.x2 && x3 == q.x3 && x4 == q.x4 && x5 == q.x5;
143 }
144 inline bool operator!= (const quintuple& q) {
145 return x1 != q.x1 || x2 != q.x2 || x3 != q.x3 || x4 != q.x4 || x5 != q.x5;
146 }
147};
148
149template <class T1, class T2, class T3, class T4, class T5>
150int
152 int h= hash (q.x1);
153 h = (h << 11) ^ (h >> 21) ^ hash (q.x2);
154 h = (h << 11) ^ (h >> 21) ^ hash (q.x3);
155 h = (h << 11) ^ (h >> 21) ^ hash (q.x4);
156 return (h << 11) ^ (h >> 21) ^ hash (q.x5);
157}
158
159template <class T1, class T2, class T3, class T4, class T5>
162 return out << "[ " << q.x1 << ", " << q.x2 << ", " << q.x3 << ", " << q.x4
163 << ", " << q.x5 << " ]";
164}
165
166template <class T1, class T2, class T3, class T4, class T5, class T6>
167class sextuple {
168public:
169 T1 x1;
170 T2 x2;
171 T3 x3;
172 T4 x4;
173 T5 x5;
174 T6 x6;
175 inline sextuple (const sextuple& s)
176 : x1 (s.x1), x2 (s.x2), x3 (s.x3), x4 (s.x4), x5 (s.x5), x6 (s.x6) {}
177 inline sextuple (const T1& y1, const T2& y2, const T3& y3, const T4& y4,
178 const T5& y5, const T6& y6)
179 : x1 (y1), x2 (y2), x3 (y3), x4 (y4), x5 (y5), x6 (y6) {}
180 inline sextuple& operator= (const sextuple& s) {
181 x1= s.x1;
182 x2= s.x2;
183 x3= s.x3;
184 x4= s.x4;
185 x5= s.x5;
186 x6= s.x6;
187 return *this;
188 }
189 inline bool operator== (const sextuple& s) {
190 return x1 == s.x1 && x2 == s.x2 && x3 == s.x3 && x4 == s.x4 && x5 == s.x5 &&
191 x6 == s.x6;
192 }
193 inline bool operator!= (const sextuple& s) {
194 return x1 != s.x1 || x2 != s.x2 || x3 != s.x3 || x4 != s.x4 || x5 != s.x5 ||
195 x6 != s.x6;
196 }
197};
198
199template <class T1, class T2, class T3, class T4, class T5, class T6>
200int
202 int h= hash (s.x1);
203 h = (h << 11) ^ (h >> 21) ^ hash (s.x2);
204 h = (h << 11) ^ (h >> 21) ^ hash (s.x3);
205 h = (h << 11) ^ (h >> 21) ^ hash (s.x4);
206 h = (h << 11) ^ (h >> 21) ^ hash (s.x5);
207 return (h << 11) ^ (h >> 21) ^ hash (s.x6);
208}
209
210template <class T1, class T2, class T3, class T4, class T5, class T6>
213 return out << "[ " << s.x1 << ", " << s.x2 << ", " << s.x3 << ", " << s.x4
214 << ", " << s.x5 << ", " << s.x6 << " ]";
215}
216
217#endif // NTUPLE_H
blackbox t[13]
The list class represents a linked list.
Definition list.hpp:48
pair(const pair &p)
Definition ntuple.hpp:20
bool operator!=(const pair &p)
Definition ntuple.hpp:28
T2 x2
Definition ntuple.hpp:19
pair(const T1 &y1, const T2 &y2)
Definition ntuple.hpp:21
bool operator==(const pair &p)
Definition ntuple.hpp:27
T1 x1
Definition ntuple.hpp:18
pair & operator=(const pair &p)
Definition ntuple.hpp:22
T2 x2
Definition ntuple.hpp:83
T1 x1
Definition ntuple.hpp:82
T4 x4
Definition ntuple.hpp:85
bool operator==(const quartet &q)
Definition ntuple.hpp:97
bool operator!=(const quartet &q)
Definition ntuple.hpp:100
T3 x3
Definition ntuple.hpp:84
quartet & operator=(const quartet &q)
Definition ntuple.hpp:90
quartet(const quartet &q)
Definition ntuple.hpp:86
quartet(const T1 &y1, const T2 &y2, const T3 &y3, const T4 &y4)
Definition ntuple.hpp:88
quintuple & operator=(const quintuple &q)
Definition ntuple.hpp:133
quintuple(const quintuple &q)
Definition ntuple.hpp:128
bool operator==(const quintuple &q)
Definition ntuple.hpp:141
bool operator!=(const quintuple &q)
Definition ntuple.hpp:144
quintuple(const T1 &y1, const T2 &y2, const T3 &y3, const T4 &y4, const T5 &y5)
Definition ntuple.hpp:130
sextuple & operator=(const sextuple &s)
Definition ntuple.hpp:180
bool operator==(const sextuple &s)
Definition ntuple.hpp:189
bool operator!=(const sextuple &s)
Definition ntuple.hpp:193
sextuple(const sextuple &s)
Definition ntuple.hpp:175
sextuple(const T1 &y1, const T2 &y2, const T3 &y3, const T4 &y4, const T5 &y5, const T6 &y6)
Definition ntuple.hpp:177
triple(const T1 &y1, const T2 &y2, const T3 &y3)
Definition ntuple.hpp:50
bool operator!=(const triple &t)
Definition ntuple.hpp:61
T1 x1
Definition ntuple.hpp:46
T2 x2
Definition ntuple.hpp:47
triple(const triple &t)
Definition ntuple.hpp:49
triple & operator=(const triple &t)
Definition ntuple.hpp:52
T3 x3
Definition ntuple.hpp:48
bool operator==(const triple &t)
Definition ntuple.hpp:58
int hash(const pair< T1, T2 > &p)
Definition ntuple.hpp:33
tm_ostream & operator<<(tm_ostream &out, const pair< T1, T2 > &p)
Definition ntuple.hpp:40