2 /******************************************************************************
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 ******************************************************************************/
16 template<class T1
, class T2
>
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
) { x1
= p
.x1
; x2
= p
.x2
; return *this; }
23 inline bool operator == (const pair
& p
) { return x1
== p
.x1
&& x2
== p
.x2
; }
24 inline bool operator != (const pair
& p
) { return x1
!= p
.x1
|| x2
!= p
.x2
; }
27 template<class T1
, class T2
> int
28 hash (const pair
<T1
,T2
>& p
) {
30 return (h1
<< 11) ^ (h1
>> 21) ^ hash (p
.x2
); }
32 template<class T1
, class T2
> inline tm_ostream
&
33 operator << (tm_ostream
& out
, const pair
<T1
,T2
>& p
) {
34 return out
<< "[ " << p
.x1
<< ", " << p
.x2
<< " ]"; }
36 template<class T1
, class T2
, class T3
>
40 inline triple (const triple
& t
):
41 x1 (t
.x1
), x2 (t
.x2
), x3 (t
.x3
) {}
42 inline triple (const T1
& y1
, const T2
& y2
, const T3
& y3
):
43 x1 (y1
), x2 (y2
), x3 (y3
) {}
44 inline triple
& operator = (const triple
& t
) {
45 x1
= t
.x1
; x2
= t
.x2
; x3
= t
.x3
; return *this; }
46 inline bool operator == (const triple
& t
) {
47 return x1
== t
.x1
&& x2
== t
.x2
&& x3
== t
.x3
; }
48 inline bool operator != (const triple
& t
) {
49 return x1
!= t
.x1
|| x2
!= t
.x2
|| x3
!= t
.x3
; }
52 template<class T1
, class T2
, class T3
> int
53 hash (const triple
<T1
,T2
,T3
>& t
) {
55 h
= (h
<< 11) ^ (h
>> 21) ^ hash (t
.x2
);
56 return (h
<< 11) ^ (h
>> 21) ^ hash (t
.x3
); }
58 template<class T1
, class T2
, class T3
> inline tm_ostream
&
59 operator << (tm_ostream
& out
, const triple
<T1
,T2
,T3
>& t
) {
60 return out
<< "[ " << t
.x1
<< ", " << t
.x2
<< ", " << t
.x3
<< " ]"; }
62 template<class T1
, class T2
, class T3
, class T4
>
65 T1 x1
; T2 x2
; T3 x3
; T4 x4
;
66 inline quartet (const quartet
& q
):
67 x1 (q
.x1
), x2 (q
.x2
), x3 (q
.x3
), x4 (q
.x4
) {}
68 inline quartet (const T1
& y1
, const T2
& y2
, const T3
& y3
, const T4
& y4
):
69 x1 (y1
), x2 (y2
), x3 (y3
), x4 (y4
) {}
70 inline quartet
& operator = (const quartet
& q
) {
71 x1
= q
.x1
; x2
= q
.x2
; x3
= q
.x3
; x4
= q
.x4
; return *this; }
72 inline bool operator == (const quartet
& q
) {
73 return x1
== q
.x1
&& x2
== q
.x2
&& x3
== q
.x3
&& x4
== q
.x4
; }
74 inline bool operator != (const quartet
& q
) {
75 return x1
!= q
.x1
|| x2
!= q
.x2
|| x3
!= q
.x3
|| x4
!= q
.x4
; }
78 template<class T1
, class T2
, class T3
, class T4
> int
79 hash (const quartet
<T1
,T2
,T3
,T4
>& q
) {
81 h
= (h
<< 11) ^ (h
>> 21) ^ hash (q
.x2
);
82 h
= (h
<< 11) ^ (h
>> 21) ^ hash (q
.x3
);
83 return (h
<< 11) ^ (h
>> 21) ^ hash (q
.x4
); }
85 template<class T1
, class T2
, class T3
, class T4
> inline tm_ostream
&
86 operator << (tm_ostream
& out
, const quartet
<T1
,T2
,T3
,T4
>& q
) {
87 return out
<< "[ " << q
.x1
<< ", " << q
.x2
88 << ", " << q
.x3
<< ", " << q
.x4
<< " ]"; }
90 template<class T1
, class T2
, class T3
, class T4
, class T5
>
93 T1 x1
; T2 x2
; T3 x3
; T4 x4
; T5 x5
;
94 inline quintuple (const quintuple
& q
):
95 x1 (q
.x1
), x2 (q
.x2
), x3 (q
.x3
), x4 (q
.x4
), x5 (q
.x5
) {}
96 inline quintuple (const T1
& y1
, const T2
& y2
, const T3
& y3
,
97 const T3
& y4
, const T5
& y5
):
98 x1 (y1
), x2 (y2
), x3 (y3
), x4 (y4
), x5 (y5
) {}
99 inline quintuple
& operator = (const quintuple
& q
) {
100 x1
= q
.x1
; x2
= q
.x2
; x3
= q
.x3
; x4
= q
.x4
; x5
= q
.x5
; return *this; }
101 inline bool operator == (const quintuple
& q
) {
102 return x1
== q
.x1
&& x2
== q
.x2
&& x3
== q
.x3
&&
103 x4
== q
.x4
&& x5
== q
.x5
; }
104 inline bool operator != (const quintuple
& q
) {
105 return x1
!= q
.x1
|| x2
!= q
.x2
|| x3
!= q
.x3
||
106 x4
!= q
.x4
|| x5
!= q
.x5
; }
109 template<class T1
, class T2
, class T3
, class T4
, class T5
> int
110 hash (const quintuple
<T1
,T2
,T3
,T4
,T5
>& q
) {
112 h
= (h
<< 11) ^ (h
>> 21) ^ hash (q
.x2
);
113 h
= (h
<< 11) ^ (h
>> 21) ^ hash (q
.x3
);
114 h
= (h
<< 11) ^ (h
>> 21) ^ hash (q
.x4
);
115 return (h
<< 11) ^ (h
>> 21) ^ hash (q
.x5
); }
117 template<class T1
, class T2
, class T3
, class T4
, class T5
> inline tm_ostream
&
118 operator << (tm_ostream
& out
, const quintuple
<T1
,T2
,T3
,T4
,T5
>& q
) {
119 return out
<< "[ " << q
.x1
<< ", " << q
.x2
<< ", " << q
.x3
120 << ", " << q
.x4
<< ", " << q
.x5
<< " ]"; }