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/memory.h>
37 
38 #include <cstddef>
39 #include <ostream>
40 
41 namespace ogdf {
42 
44 
48 template<class E1, class E2>
49 class Tuple2 {
50 public:
51  E1 m_x1;
52  E2 m_x2;
53 
55  Tuple2() = default;
56 
58  Tuple2(const E1& y1, const E2& y2) : m_x1(y1), m_x2(y2) { }
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 
73 };
74 
76 template<class E1, class E2>
77 bool operator==(const Tuple2<E1, E2>& t1, const Tuple2<E1, E2>& t2) {
78  return t1.x1() == t2.x1() && t1.x2() == t2.x2();
79 }
80 
82 template<class E1, class E2>
83 bool operator!=(const Tuple2<E1, E2>& t1, const Tuple2<E1, E2>& t2) {
84  return t1.x1() != t2.x1() || t1.x2() != t2.x2();
85 }
86 
88 template<class E1, class E2>
89 std::ostream& operator<<(std::ostream& os, const Tuple2<E1, E2>& t2) {
90  os << "(" << t2.x1() << " " << t2.x2() << ")";
91  return os;
92 }
93 
94 template<typename K1_, typename K2_, typename Hash1_ = DefHashFunc<K1_>, typename Hash2_ = DefHashFunc<K2_>>
96 public:
98 
99  HashFuncTuple(const Hash1_& hash1, const Hash2_& hash2) : m_hash1(hash1), m_hash2(hash2) { }
100 
101  size_t hash(const Tuple2<K1_, K2_>& key) const {
102  return 23 * m_hash1.hash(key.x1()) + 443 * m_hash2.hash(key.x2());
103  }
104 
105 private:
106  Hash1_ m_hash1;
107  Hash2_ m_hash2;
108 };
109 
110 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::HashFuncTuple::HashFuncTuple
HashFuncTuple(const Hash1_ &hash1, const Hash2_ &hash2)
Definition: tuples.h:99
ogdf::Tuple2::x1
E1 & x1()
Returns a reference the first element.
Definition: tuples.h:67
Hashing.h
Declaration of classes used for hashing.
ogdf::Tuple2
Tuples of two elements (2-tuples).
Definition: tuples.h:49
ogdf::HashFuncTuple::HashFuncTuple
HashFuncTuple()
Definition: tuples.h:97
ogdf::operator==
bool operator==(const Tuple2< E1, E2 > &t1, const Tuple2< E1, E2 > &t2)
Equality operator for 2-tuples.
Definition: tuples.h:77
OGDF_NEW_DELETE
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
Definition: memory.h:85
ogdf::HashFuncTuple
Definition: tuples.h:95
ogdf::HashFuncTuple::m_hash2
Hash2_ m_hash2
Definition: tuples.h:107
ogdf::Tuple2::m_x2
E2 m_x2
The second element.
Definition: tuples.h:52
ogdf::Tuple2::x2
const E2 & x2() const
Returns a reference the second element.
Definition: tuples.h:64
ogdf::Tuple2::Tuple2
Tuple2(const E1 &y1, const E2 &y2)
Constructs a 2-tuple for given values.
Definition: tuples.h:58
ogdf::operator<<
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition: Array.h:983
ogdf::operator!=
bool operator!=(const Tuple2< E1, E2 > &t1, const Tuple2< E1, E2 > &t2)
Inequality operator for 2-tuples.
Definition: tuples.h:83
ogdf::HashFuncTuple::m_hash1
Hash1_ m_hash1
Definition: tuples.h:106
ogdf::Tuple2::x2
E2 & x2()
Returns a reference the second element.
Definition: tuples.h:70
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:61
ogdf::Tuple2::m_x1
E1 m_x1
The first element.
Definition: tuples.h:51
ogdf::HashFuncTuple::hash
size_t hash(const Tuple2< K1_, K2_ > &key) const
Definition: tuples.h:101
memory.h
Declaration of memory manager for allocating small pieces of memory.