Back to index

texmacs  1.0.7.15
ntuple.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : ntuple.hpp
00004 * DESCRIPTION: Pairs, triples and quartets
00005 * COPYRIGHT  : (C) 2007  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #ifndef NTUPLE_H
00013 #define NTUPLE_H
00014 #include "basic.hpp"
00015 
00016 template<class T1, class T2>
00017 class pair {
00018 public:
00019   T1 x1; T2 x2;
00020   inline pair (const pair& p): x1 (p.x1), x2 (p.x2) {}
00021   inline pair (const T1& y1, const T2& y2): x1 (y1), x2 (y2) {}
00022   inline pair& operator = (const pair& p) { x1= p.x1; x2= p.x2; return *this; }
00023   inline bool operator == (const pair& p) { return x1 == p.x1 && x2 == p.x2; }
00024   inline bool operator != (const pair& p) { return x1 != p.x1 || x2 != p.x2; }
00025 };
00026 
00027 template<class T1, class T2> int
00028 hash (const pair<T1,T2>& p) {
00029   int h1= hash (p.x1);
00030   return (h1 << 11) ^ (h1 >> 21) ^ hash (p.x2); }
00031 
00032 template<class T1, class T2> inline tm_ostream&
00033 operator << (tm_ostream& out, const pair<T1,T2>& p) {
00034   return out << "[ " << p.x1 << ", " << p.x2 << " ]"; }
00035 
00036 template<class T1, class T2, class T3>
00037 class triple {
00038 public:
00039   T1 x1; T2 x2; T3 x3;
00040   inline triple (const triple& t):
00041     x1 (t.x1), x2 (t.x2), x3 (t.x3) {}
00042   inline triple (const T1& y1, const T2& y2, const T3& y3):
00043     x1 (y1), x2 (y2), x3 (y3) {}
00044   inline triple& operator = (const triple& t) {
00045     x1= t.x1; x2= t.x2; x3= t.x3; return *this; }
00046   inline bool operator == (const triple& t) {
00047     return x1 == t.x1 && x2 == t.x2 && x3 == t.x3; }
00048   inline bool operator != (const triple& t) {
00049     return x1 != t.x1 || x2 != t.x2 || x3 != t.x3; }
00050 };
00051 
00052 template<class T1, class T2, class T3> int
00053 hash (const triple<T1,T2,T3>& t) {
00054   int h= hash (t.x1);
00055   h= (h << 11) ^ (h >> 21) ^ hash (t.x2);
00056   return (h << 11) ^ (h >> 21) ^ hash (t.x3); }
00057 
00058 template<class T1, class T2, class T3> inline tm_ostream&
00059 operator << (tm_ostream& out, const triple<T1,T2,T3>& t) {
00060   return out << "[ " << t.x1 << ", " << t.x2 << ", " << t.x3 << " ]"; }
00061 
00062 template<class T1, class T2, class T3, class T4>
00063 class quartet {
00064 public:
00065   T1 x1; T2 x2; T3 x3; T4 x4;
00066   inline quartet (const quartet& q):
00067     x1 (q.x1), x2 (q.x2), x3 (q.x3), x4 (q.x4) {}
00068   inline quartet (const T1& y1, const T2& y2, const T3& y3, const T4& y4):
00069     x1 (y1), x2 (y2), x3 (y3), x4 (y4) {}
00070   inline quartet& operator = (const quartet& q) {
00071     x1= q.x1; x2= q.x2; x3= q.x3; x4= q.x4; return *this; }
00072   inline bool operator == (const quartet& q) {
00073     return x1 == q.x1 && x2 == q.x2 && x3 == q.x3 && x4 == q.x4; }
00074   inline bool operator != (const quartet& q) {
00075     return x1 != q.x1 || x2 != q.x2 || x3 != q.x3 || x4 != q.x4; }
00076 };
00077 
00078 template<class T1, class T2, class T3, class T4> int
00079 hash (const quartet<T1,T2,T3,T4>& q) {
00080   int h= hash (q.x1);
00081   h= (h << 11) ^ (h >> 21) ^ hash (q.x2);
00082   h= (h << 11) ^ (h >> 21) ^ hash (q.x3);
00083   return (h << 11) ^ (h >> 21) ^ hash (q.x4); }
00084 
00085 template<class T1, class T2, class T3, class T4> inline tm_ostream&
00086 operator << (tm_ostream& out, const quartet<T1,T2,T3,T4>& q) {
00087   return out << "[ " << q.x1 << ", " << q.x2
00088             << ", " << q.x3 << ", " << q.x4 << " ]"; }
00089 
00090 template<class T1, class T2, class T3, class T4, class T5>
00091 class quintuple {
00092 public:
00093   T1 x1; T2 x2; T3 x3; T4 x4; T5 x5;
00094   inline quintuple (const quintuple& q):
00095     x1 (q.x1), x2 (q.x2), x3 (q.x3), x4 (q.x4), x5 (q.x5) {}
00096   inline quintuple (const T1& y1, const T2& y2, const T3& y3,
00097                   const T4& y4, const T5& y5):
00098     x1 (y1), x2 (y2), x3 (y3), x4 (y4), x5 (y5) {}
00099   inline quintuple& operator = (const quintuple& q) {
00100     x1= q.x1; x2= q.x2; x3= q.x3; x4= q.x4; x5= q.x5; return *this; }
00101   inline bool operator == (const quintuple& q) {
00102     return x1 == q.x1 && x2 == q.x2 && x3 == q.x3 &&
00103            x4 == q.x4 && x5 == q.x5; }
00104   inline bool operator != (const quintuple& q) {
00105     return x1 != q.x1 || x2 != q.x2 || x3 != q.x3 ||
00106            x4 != q.x4 || x5 != q.x5; }
00107 };
00108 
00109 template<class T1, class T2, class T3, class T4, class T5> int
00110 hash (const quintuple<T1,T2,T3,T4,T5>& q) {
00111   int h= hash (q.x1);
00112   h= (h << 11) ^ (h >> 21) ^ hash (q.x2);
00113   h= (h << 11) ^ (h >> 21) ^ hash (q.x3);
00114   h= (h << 11) ^ (h >> 21) ^ hash (q.x4);
00115   return (h << 11) ^ (h >> 21) ^ hash (q.x5); }
00116 
00117 template<class T1, class T2, class T3, class T4, class T5> inline tm_ostream&
00118 operator << (tm_ostream& out, const quintuple<T1,T2,T3,T4,T5>& q) {
00119   return out << "[ " << q.x1 << ", " << q.x2 << ", " << q.x3
00120             << ", " << q.x4 << ", " << q.x5 << " ]"; }
00121 
00122 #endif // NTUPLE_H