Open
Graph Drawing
Framework

 v.2012.07
 

tuples.h
Go to the documentation of this file.
1 /*
2  * $Revision: 2615 $
3  *
4  * last checkin:
5  * $Author: gutwenger $
6  * $Date: 2012-07-16 14:23:36 +0200 (Mo, 16. Jul 2012) $
7  ***************************************************************/
8 
45 #ifdef _MSC_VER
46 #pragma once
47 #endif
48 
49 #ifndef OGDF_TUPLE_H
50 #define OGDF_TUPLE_H
51 
52 
53 #include <ogdf/basic/basic.h>
54 #include <ogdf/basic/Hashing.h>
55 
56 
57 namespace ogdf {
58 
60 
64 template<class E1, class E2> class Tuple2 {
65 public:
66  E1 m_x1;
67  E2 m_x2;
68 
70  Tuple2() { }
72  Tuple2(const E1 &y1, const E2 &y2) : m_x1(y1), m_x2(y2) { }
74  Tuple2(const Tuple2<E1,E2> &t2) : m_x1(t2.m_x1), m_x2(t2.m_x2) { }
75 
77  const E1 &x1() const { return m_x1; }
79  const E2 &x2() const { return m_x2; }
80 
82  E1 &x1() { return m_x1; }
84  E2 &x2() { return m_x2; }
85 
86  // default assignment operator
87 
89 };
90 
92 template<class E1, class E2>
93 bool operator==(const Tuple2<E1,E2> &t1, const Tuple2<E1,E2> &t2)
94 {
95  return t1.x1() == t2.x1() && t1.x2() == t2.x2();
96 }
97 
99 template<class E1, class E2>
100 bool operator!=(const Tuple2<E1,E2> &t1, const Tuple2<E1,E2> &t2)
101 {
102  return t1.x1() != t2.x1() || t1.x2() != t2.x2();
103 }
104 
106 template<class E1, class E2>
107 ostream &operator<<(ostream &os, const Tuple2<E1,E2> &t2)
108 {
109  os << "(" << t2.x1() << " " << t2.x2() << ")";
110  return os;
111 }
112 
113 
115 
120 template<class E1, class E2, class E3> class Tuple3 {
121 public:
122  E1 m_x1;
123  E2 m_x2;
124  E3 m_x3;
125 
127  Tuple3() { }
129  Tuple3(const E1 &y1, const E2 &y2, const E3 &y3) :
130  m_x1(y1), m_x2(y2), m_x3(y3) { }
133  m_x1(t3.m_x1), m_x2(t3.m_x2), m_x3(t3.m_x3) { }
134 
136  const E1 &x1() const { return m_x1; }
138  const E2 &x2() const { return m_x2; }
140  const E3 &x3() const { return m_x3; }
141 
143  E1 &x1() { return m_x1; }
145  E2 &x2() { return m_x2; }
147  E3 &x3() { return m_x3; }
148 
149  // default assignment operator
150 
152 };
153 
155 template<class E1, class E2, class E3>
156 bool operator==(const Tuple3<E1,E2,E3> &t1, const Tuple3<E1,E2,E3> &t2)
157 {
158  return t1.x1() == t2.x1() && t1.x2() == t2.x2() && t1.x3() == t2.x3();
159 }
160 
162 template<class E1, class E2, class E3>
163 bool operator!=(const Tuple3<E1,E2,E3> &t1, const Tuple3<E1,E2,E3> &t2)
164 {
165  return t1.x1() != t2.x1() || t1.x2() != t2.x2() || t1.x3() != t2.x3();
166 }
167 
169 template<class E1, class E2, class E3>
170 ostream &operator<<(ostream &os, const Tuple3<E1,E2,E3> &t3)
171 {
172  os << "(" << t3.x1() << " " << t3.x2() << " " << t3.x3() << ")";
173  return os;
174 }
175 
176 
178 
184 template<class E1, class E2, class E3, class E4> class Tuple4 {
185 public:
186  E1 m_x1;
187  E2 m_x2;
188  E3 m_x3;
189  E4 m_x4;
190 
192  Tuple4() { }
194  Tuple4(const E1 &y1, const E2 &y2, const E3 &y3, const E4 &y4) :
195  m_x1(y1), m_x2(y2), m_x3(y3), m_x4(y4) { }
198  m_x1(t4.m_x1), m_x2(t4.m_x2), m_x3(t4.m_x3), m_x4(t4.m_x4) { }
199 
201  const E1 &x1() const { return m_x1; }
203  const E2 &x2() const { return m_x2; }
205  const E3 &x3() const { return m_x3; }
207  const E4 &x4() const { return m_x4; }
208 
210  E1 &x1() { return m_x1; }
212  E2 &x2() { return m_x2; }
214  E3 &x3() { return m_x3; }
216  E4 &x4() { return m_x4; }
217 
218  // default assignment operator
219 
221 };
222 
224 template<class E1, class E2, class E3, class E4>
226 {
227  return t1.x1() == t2.x1() && t1.x2() == t2.x2() &&
228  t1.x3() == t2.x3() && t1.x4() == t2.x4();
229 }
230 
232 template<class E1, class E2, class E3, class E4>
234 {
235  return t1.x1() != t2.x1() || t1.x2() != t2.x2() ||
236  t1.x3() != t2.x3() || t1.x4() != t2.x4();
237 }
238 
240 template<class E1, class E2, class E3, class E4>
241 ostream &operator<<(ostream &os, const Tuple4<E1,E2,E3,E4> &t4)
242 {
243  os << "(" << t4.x1() << " " << t4.x2() << " " <<
244  t4.x3() << " " << t4.x4() << ")";
245  return os;
246 }
247 
248 template<typename K1_, typename K2_,
249  typename Hash1_ = DefHashFunc<K1_>,
250  typename Hash2_ = DefHashFunc<K2_> >
252 {
253 public:
255 
256  HashFuncTuple(const Hash1_ &hash1, const Hash2_ &hash2)
257  : m_hash1(hash1), m_hash2(hash2) { }
258 
259  size_t hash(const Tuple2<K1_,K2_> &key) const {
260  return 23*m_hash1.hash(key.x1()) + 443*m_hash2.hash(key.x2());
261  }
262 
263 private:
264  Hash1_ m_hash1;
265  Hash2_ m_hash2;
266 };
267 
268 } // namespace ogdf
269 
270 
271 #endif