Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

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