Open
Graph Drawing
Framework

 v.2012.05
 

tuples.h
Go to the documentation of this file.
00001 /*
00002  * $Revision: 2299 $
00003  * 
00004  * last checkin:
00005  *   $Author: gutwenger $ 
00006  *   $Date: 2012-05-07 15:57:08 +0200 (Mon, 07 May 2012) $ 
00007  ***************************************************************/
00008  
00044 #ifdef _MSC_VER
00045 #pragma once
00046 #endif
00047 
00048 #ifndef OGDF_TUPLE_H
00049 #define OGDF_TUPLE_H
00050 
00051 
00052 #include <ogdf/basic/basic.h>
00053 #include <ogdf/basic/Hashing.h>
00054 
00055 
00056 namespace ogdf {
00057 
00059 template<class E1, class E2> class Tuple2 {
00060 public:
00061     E1 m_x1; 
00062     E2 m_x2; 
00063 
00065     Tuple2() { }
00067     Tuple2(const E1 &y1, const E2 &y2) : m_x1(y1), m_x2(y2) { }
00069     Tuple2(const Tuple2<E1,E2> &t2) : m_x1(t2.m_x1), m_x2(t2.m_x2) { }
00070 
00072     const E1 &x1() const { return m_x1; }
00074     const E2 &x2() const { return m_x2; }
00075 
00077     E1 &x1() { return m_x1; }
00079     E2 &x2() { return m_x2; }
00080 
00081     // default assignment operator
00082 
00083     OGDF_NEW_DELETE
00084 };
00085 
00087 template<class E1, class E2>
00088 bool operator==(const Tuple2<E1,E2> &t1, const Tuple2<E1,E2> &t2)
00089 {
00090     return t1.x1() == t2.x1() && t1.x2() == t2.x2();
00091 }
00092 
00094 template<class E1, class E2>
00095 bool operator!=(const Tuple2<E1,E2> &t1, const Tuple2<E1,E2> &t2)
00096 {
00097     return t1.x1() != t2.x1() || t1.x2() != t2.x2();
00098 }
00099 
00101 template<class E1, class E2>
00102 ostream &operator<<(ostream &os, const Tuple2<E1,E2> &t2)
00103 {
00104     os << "(" << t2.x1() << " " << t2.x2() << ")";
00105     return os;
00106 }
00107 
00108 
00110 template<class E1, class E2, class E3> class Tuple3 {
00111 public:
00112     E1 m_x1; 
00113     E2 m_x2; 
00114     E3 m_x3; 
00115 
00117     Tuple3() { }
00119     Tuple3(const E1 &y1, const E2 &y2, const E3 &y3) :
00120         m_x1(y1), m_x2(y2), m_x3(y3) { }
00122     Tuple3(const Tuple3<E1,E2,E3> &t3) :
00123         m_x1(t3.m_x1), m_x2(t3.m_x2), m_x3(t3.m_x3) { }
00124 
00126     const E1 &x1() const { return m_x1; }
00128     const E2 &x2() const { return m_x2; }
00130     const E3 &x3() const { return m_x3; }
00131 
00133     E1 &x1() { return m_x1; }
00135     E2 &x2() { return m_x2; }
00137     E3 &x3() { return m_x3; }
00138 
00139     // default assignment operator
00140 
00141     OGDF_NEW_DELETE
00142 };
00143 
00145 template<class E1, class E2, class E3>
00146 bool operator==(const Tuple3<E1,E2,E3> &t1, const Tuple3<E1,E2,E3> &t2)
00147 {
00148     return t1.x1() == t2.x1() && t1.x2() == t2.x2() && t1.x3() == t2.x3();
00149 }
00150 
00152 template<class E1, class E2, class E3>
00153 bool operator!=(const Tuple3<E1,E2,E3> &t1, const Tuple3<E1,E2,E3> &t2)
00154 {
00155     return t1.x1() != t2.x1() || t1.x2() != t2.x2() || t1.x3() != t2.x3();
00156 }
00157 
00159 template<class E1, class E2, class E3>
00160 ostream &operator<<(ostream &os, const Tuple3<E1,E2,E3> &t3)
00161 {
00162     os << "(" << t3.x1() << " " << t3.x2() << " " << t3.x3() << ")";
00163     return os;
00164 }
00165 
00166 
00168 template<class E1, class E2, class E3, class E4> class Tuple4 {
00169 public:
00170     E1 m_x1; 
00171     E2 m_x2; 
00172     E3 m_x3; 
00173     E4 m_x4; 
00174 
00176     Tuple4() { }
00178     Tuple4(const E1 &y1, const E2 &y2, const E3 &y3, const E4 &y4) :
00179         m_x1(y1), m_x2(y2), m_x3(y3), m_x4(y4) { }
00181     Tuple4(const Tuple4<E1,E2,E3,E4> &t4) :
00182         m_x1(t4.m_x1), m_x2(t4.m_x2), m_x3(t4.m_x3), m_x4(t4.m_x4) { }
00183 
00185     const E1 &x1() const { return m_x1; }
00187     const E2 &x2() const { return m_x2; }
00189     const E3 &x3() const { return m_x3; }
00191     const E4 &x4() const { return m_x4; }
00192 
00194     E1 &x1() { return m_x1; }
00196     E2 &x2() { return m_x2; }
00198     E3 &x3() { return m_x3; }
00200     E4 &x4() { return m_x4; }
00201 
00202     // default assignment operator
00203 
00204     OGDF_NEW_DELETE
00205 };
00206 
00208 template<class E1, class E2, class E3, class E4>
00209 bool operator==(const Tuple4<E1,E2,E3,E4> &t1, const Tuple4<E1,E2,E3,E4> &t2)
00210 {
00211     return t1.x1() == t2.x1() && t1.x2() == t2.x2() &&
00212         t1.x3() == t2.x3() && t1.x4() == t2.x4();
00213 }
00214 
00216 template<class E1, class E2, class E3, class E4>
00217 bool operator!=(const Tuple4<E1,E2,E3,E4> &t1, const Tuple4<E1,E2,E3,E4> &t2)
00218 {
00219     return t1.x1() != t2.x1() || t1.x2() != t2.x2() ||
00220         t1.x3() != t2.x3() || t1.x4() != t2.x4();
00221 }
00222 
00224 template<class E1, class E2, class E3, class E4>
00225 ostream &operator<<(ostream &os, const Tuple4<E1,E2,E3,E4> &t4)
00226 {
00227     os << "(" << t4.x1() << " " << t4.x2() << " " <<
00228         t4.x3() << " " << t4.x4() << ")";
00229     return os;
00230 }
00231 
00232 template<typename K1_, typename K2_,
00233     typename Hash1_ = DefHashFunc<K1_>,
00234     typename Hash2_ = DefHashFunc<K2_> >
00235 class HashFuncTuple
00236 {
00237 public:
00238     HashFuncTuple() { }
00239 
00240     HashFuncTuple(const Hash1_ &hash1, const Hash2_ &hash2)
00241         : m_hash1(hash1), m_hash2(hash2) { }
00242 
00243     size_t hash(const Tuple2<K1_,K2_> &key) const {
00244         return 23*m_hash1.hash(key.x1()) + 443*m_hash2.hash(key.x2());
00245     }
00246 
00247 private:
00248     Hash1_ m_hash1;
00249     Hash2_ m_hash2;
00250 };
00251 
00252 } // namespace ogdf
00253 
00254 
00255 #endif