# OpenGraph DrawingFramework

v. 2023.09 (Elderberry)

Loading...
Searching...
No Matches
tuples.h
Go to the documentation of this file.
1
33#pragma once
34
35#include <ogdf/basic/Hashing.h>
36#include <ogdf/basic/basic.h>
37
38namespace ogdf {
39
41
45template<class E1, class E2>
46class Tuple2 {
47public:
48 E1 m_x1;
49 E2 m_x2;
50
52 Tuple2() { }
53
55 Tuple2(const E1& y1, const E2& y2) : m_x1(y1), m_x2(y2) { }
56
58 Tuple2(const Tuple2<E1, E2>& t2) : m_x1(t2.m_x1), m_x2(t2.m_x2) { }
59
61 const E1& x1() const { return m_x1; }
62
64 const E2& x2() const { return m_x2; }
65
67 E1& x1() { return m_x1; }
68
70 E2& x2() { return m_x2; }
71
72 // default assignment operator
73 Tuple2& operator=(const Tuple2<E1, E2>&) = default;
74
76};
77
79template<class E1, class E2>
80bool operator==(const Tuple2<E1, E2>& t1, const Tuple2<E1, E2>& t2) {
81 return t1.x1() == t2.x1() && t1.x2() == t2.x2();
82}
83
85template<class E1, class E2>
86bool operator!=(const Tuple2<E1, E2>& t1, const Tuple2<E1, E2>& t2) {
87 return t1.x1() != t2.x1() || t1.x2() != t2.x2();
88}
89
91template<class E1, class E2>
92std::ostream& operator<<(std::ostream& os, const Tuple2<E1, E2>& t2) {
93 os << "(" << t2.x1() << " " << t2.x2() << ")";
94 return os;
95}
96
97template<typename K1_, typename K2_, typename Hash1_ = DefHashFunc<K1_>, typename Hash2_ = DefHashFunc<K2_>>
99public:
101
103
104 size_t hash(const Tuple2<K1_, K2_>& key) const {
105 return 23 * m_hash1.hash(key.x1()) + 443 * m_hash2.hash(key.x2());
106 }
107
108private:
111};
112
113}
Declaration of classes used for hashing.
Basic declarations, included by all source files.
HashFuncTuple(const Hash1_ &hash1, const Hash2_ &hash2)
Definition tuples.h:102
size_t hash(const Tuple2< K1_, K2_ > &key) const
Definition tuples.h:104
Tuples of two elements (2-tuples).
Definition tuples.h:46
Tuple2 & operator=(const Tuple2< E1, E2 > &)=default
Tuple2(const E1 &y1, const E2 &y2)
Constructs a 2-tuple for given values.
Definition tuples.h:55
const E1 & x1() const
Returns a reference the first element.
Definition tuples.h:61
const E2 & x2() const
Returns a reference the second element.
Definition tuples.h:64
E1 & x1()
Returns a reference the first element.
Definition tuples.h:67
Tuple2(const Tuple2< E1, E2 > &t2)
Constructs a 2-tuple that is a copy of t2.
Definition tuples.h:58
E2 m_x2
The second element.
Definition tuples.h:49
Tuple2()
Constructs a 2-tuple using default constructors.
Definition tuples.h:52
E2 & x2()
Returns a reference the second element.
Definition tuples.h:70
E1 m_x1
The first element.
Definition tuples.h:48
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
Definition memory.h:84
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition Array.h:978
bool operator!=(const Tuple2< E1, E2 > &t1, const Tuple2< E1, E2 > &t2)
Inequality operator for 2-tuples.
Definition tuples.h:86
bool operator==(const Tuple2< E1, E2 > &t1, const Tuple2< E1, E2 > &t2)
Equality operator for 2-tuples.
Definition tuples.h:80