Open
Graph Drawing
Framework

 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/memory.h>
37
38#include <cstddef>
39#include <ostream>
40
41namespace ogdf {
42
44
48template<class E1, class E2>
49class Tuple2 {
50public:
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
76template<class E1, class E2>
77bool operator==(const Tuple2<E1, E2>& t1, const Tuple2<E1, E2>& t2) {
78 return t1.x1() == t2.x1() && t1.x2() == t2.x2();
79}
80
82template<class E1, class E2>
83bool operator!=(const Tuple2<E1, E2>& t1, const Tuple2<E1, E2>& t2) {
84 return t1.x1() != t2.x1() || t1.x2() != t2.x2();
85}
86
88template<class E1, class E2>
89std::ostream& operator<<(std::ostream& os, const Tuple2<E1, E2>& t2) {
90 os << "(" << t2.x1() << " " << t2.x2() << ")";
91 return os;
92}
93
94template<typename K1_, typename K2_, typename Hash1_ = DefHashFunc<K1_>, typename Hash2_ = DefHashFunc<K2_>>
96public:
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
105private:
106 Hash1_ m_hash1;
107 Hash2_ m_hash2;
108};
109
110}
Declaration of classes used for hashing.
HashFuncTuple(const Hash1_ &hash1, const Hash2_ &hash2)
Definition tuples.h:99
size_t hash(const Tuple2< K1_, K2_ > &key) const
Definition tuples.h:101
Tuples of two elements (2-tuples).
Definition tuples.h:49
Tuple2(const E1 &y1, const E2 &y2)
Constructs a 2-tuple for given values.
Definition tuples.h:58
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
E2 m_x2
The second element.
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:51
Tuple2()=default
Constructs a 2-tuple using default constructors.
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
Definition memory.h:85
Declaration of memory manager for allocating small pieces of memory.
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:983
bool operator!=(const Tuple2< E1, E2 > &t1, const Tuple2< E1, E2 > &t2)
Inequality operator for 2-tuples.
Definition tuples.h:83
bool operator==(const Tuple2< E1, E2 > &t1, const Tuple2< E1, E2 > &t2)
Equality operator for 2-tuples.
Definition tuples.h:77