Open
Graph Drawing
Framework

 v.2010.10
 

tuples.h

Go to the documentation of this file.
00001 /*
00002  * $Revision: 2027 $
00003  * 
00004  * last checkin:
00005  *   $Author: gutwenger $ 
00006  *   $Date: 2010-09-01 11:55:17 +0200 (Wed, 01 Sep 2010) $ 
00007  ***************************************************************/
00008  
00054 #ifdef _MSC_VER
00055 #pragma once
00056 #endif
00057 
00058 #ifndef OGDF_TUPLE_H
00059 #define OGDF_TUPLE_H
00060 
00061 
00062 #include <ogdf/basic/basic.h>
00063 #include <ogdf/basic/Hashing.h>
00064 
00065 
00066 namespace ogdf {
00067 
00069 template<class E1, class E2> class Tuple2 {
00070 public:
00071     E1 m_x1; 
00072     E2 m_x2; 
00073 
00075     Tuple2() { }
00077     Tuple2(const E1 &y1, const E2 &y2) : m_x1(y1), m_x2(y2) { }
00079     Tuple2(const Tuple2<E1,E2> &t2) : m_x1(t2.m_x1), m_x2(t2.m_x2) { }
00080 
00082     const E1 &x1() const { return m_x1; }
00084     const E2 &x2() const { return m_x2; }
00085 
00087     E1 &x1() { return m_x1; }
00089     E2 &x2() { return m_x2; }
00090 
00091     // default assignment operator
00092 
00093     OGDF_NEW_DELETE
00094 };
00095 
00097 template<class E1, class E2>
00098 bool operator==(const Tuple2<E1,E2> &t1, const Tuple2<E1,E2> &t2)
00099 {
00100     return t1.x1() == t2.x1() && t1.x2() == t2.x2();
00101 }
00102 
00104 template<class E1, class E2>
00105 bool operator!=(const Tuple2<E1,E2> &t1, const Tuple2<E1,E2> &t2)
00106 {
00107     return t1.x1() != t2.x1() || t1.x2() != t2.x2();
00108 }
00109 
00111 template<class E1, class E2>
00112 ostream &operator<<(ostream &os, const Tuple2<E1,E2> &t2)
00113 {
00114     os << "(" << t2.x1() << " " << t2.x2() << ")";
00115     return os;
00116 }
00117 
00118 
00120 template<class E1, class E2, class E3> class Tuple3 {
00121 public:
00122     E1 m_x1; 
00123     E2 m_x2; 
00124     E3 m_x3; 
00125 
00127     Tuple3() { }
00129     Tuple3(const E1 &y1, const E2 &y2, const E3 &y3) :
00130         m_x1(y1), m_x2(y2), m_x3(y3) { }
00132     Tuple3(const Tuple3<E1,E2,E3> &t3) :
00133         m_x1(t3.m_x1), m_x2(t3.m_x2), m_x3(t3.m_x3) { }
00134 
00136     const E1 &x1() const { return m_x1; }
00138     const E2 &x2() const { return m_x2; }
00140     const E3 &x3() const { return m_x3; }
00141 
00143     E1 &x1() { return m_x1; }
00145     E2 &x2() { return m_x2; }
00147     E3 &x3() { return m_x3; }
00148 
00149     // default assignment operator
00150 
00151     OGDF_NEW_DELETE
00152 };
00153 
00155 template<class E1, class E2, class E3>
00156 bool operator==(const Tuple3<E1,E2,E3> &t1, const Tuple3<E1,E2,E3> &t2)
00157 {
00158     return t1.x1() == t2.x1() && t1.x2() == t2.x2() && t1.x3() == t2.x3();
00159 }
00160 
00162 template<class E1, class E2, class E3>
00163 bool operator!=(const Tuple3<E1,E2,E3> &t1, const Tuple3<E1,E2,E3> &t2)
00164 {
00165     return t1.x1() != t2.x1() || t1.x2() != t2.x2() || t1.x3() != t2.x3();
00166 }
00167 
00169 template<class E1, class E2, class E3>
00170 ostream &operator<<(ostream &os, const Tuple3<E1,E2,E3> &t3)
00171 {
00172     os << "(" << t3.x1() << " " << t3.x2() << " " << t3.x3() << ")";
00173     return os;
00174 }
00175 
00176 
00178 template<class E1, class E2, class E3, class E4> class Tuple4 {
00179 public:
00180     E1 m_x1; 
00181     E2 m_x2; 
00182     E3 m_x3; 
00183     E4 m_x4; 
00184 
00186     Tuple4() { }
00188     Tuple4(const E1 &y1, const E2 &y2, const E3 &y3, const E4 &y4) :
00189         m_x1(y1), m_x2(y2), m_x3(y3), m_x4(y4) { }
00191     Tuple4(const Tuple4<E1,E2,E3,E4> &t4) :
00192         m_x1(t4.m_x1), m_x2(t4.m_x2), m_x3(t4.m_x3), m_x4(t4.m_x4) { }
00193 
00195     const E1 &x1() const { return m_x1; }
00197     const E2 &x2() const { return m_x2; }
00199     const E3 &x3() const { return m_x3; }
00201     const E4 &x4() const { return m_x4; }
00202 
00204     E1 &x1() { return m_x1; }
00206     E2 &x2() { return m_x2; }
00208     E3 &x3() { return m_x3; }
00210     E4 &x4() { return m_x4; }
00211 
00212     // default assignment operator
00213 
00214     OGDF_NEW_DELETE
00215 };
00216 
00218 template<class E1, class E2, class E3, class E4>
00219 bool operator==(const Tuple4<E1,E2,E3,E4> &t1, const Tuple4<E1,E2,E3,E4> &t2)
00220 {
00221     return t1.x1() == t2.x1() && t1.x2() == t2.x2() &&
00222         t1.x3() == t2.x3() && t1.x4() == t2.x4();
00223 }
00224 
00226 template<class E1, class E2, class E3, class E4>
00227 bool operator!=(const Tuple4<E1,E2,E3,E4> &t1, const Tuple4<E1,E2,E3,E4> &t2)
00228 {
00229     return t1.x1() != t2.x1() || t1.x2() != t2.x2() ||
00230         t1.x3() != t2.x3() || t1.x4() != t2.x4();
00231 }
00232 
00234 template<class E1, class E2, class E3, class E4>
00235 ostream &operator<<(ostream &os, const Tuple4<E1,E2,E3,E4> &t4)
00236 {
00237     os << "(" << t4.x1() << " " << t4.x2() << " " <<
00238         t4.x3() << " " << t4.x4() << ")";
00239     return os;
00240 }
00241 
00242 template<typename K1_, typename K2_,
00243     typename Hash1_ = DefHashFunc<K1_>,
00244     typename Hash2_ = DefHashFunc<K2_> >
00245 class HashFuncTuple
00246 {
00247 public:
00248     HashFuncTuple() { }
00249 
00250     HashFuncTuple(const Hash1_ &hash1, const Hash2_ &hash2)
00251         : m_hash1(hash1), m_hash2(hash2) { }
00252 
00253     size_t hash(const Tuple2<K1_,K2_> &key) const {
00254         return 23*m_hash1.hash(key.x1()) + 443*m_hash2.hash(key.x2());
00255     }
00256 
00257 private:
00258     Hash1_ m_hash1;
00259     Hash2_ m_hash2;
00260 };
00261 
00262 } // namespace ogdf
00263 
00264 
00265 #endif