Open
Graph Drawing
Framework

 v. 2022.02 (Dogwood)
 

tuples.h
Go to the documentation of this file.
1 
33 #pragma once
34 
35 #include <ogdf/basic/basic.h>
36 #include <ogdf/basic/Hashing.h>
37 
38 
39 namespace ogdf {
40 
42 
46 template<class E1, class E2> class Tuple2 {
47 public:
48  E1 m_x1;
49  E2 m_x2;
50 
52  Tuple2() { }
54  Tuple2(const E1 &y1, const E2 &y2) : m_x1(y1), m_x2(y2) { }
56  Tuple2(const Tuple2<E1,E2> &t2) : m_x1(t2.m_x1), m_x2(t2.m_x2) { }
57 
59  const E1 &x1() const { return m_x1; }
61  const E2 &x2() const { return m_x2; }
62 
64  E1 &x1() { return m_x1; }
66  E2 &x2() { return m_x2; }
67 
68  // default assignment operator
69  Tuple2& operator=(const Tuple2<E1,E2>&) = default;
70 
72 };
73 
75 template<class E1, class E2>
76 bool operator==(const Tuple2<E1,E2> &t1, const Tuple2<E1,E2> &t2)
77 {
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 {
85  return t1.x1() != t2.x1() || t1.x2() != t2.x2();
86 }
87 
89 template<class E1, class E2>
90 std::ostream &operator<<(std::ostream &os, const Tuple2<E1,E2> &t2)
91 {
92  os << "(" << t2.x1() << " " << t2.x2() << ")";
93  return os;
94 }
95 
96 
97 
98 template<typename K1_, typename K2_,
99  typename Hash1_ = DefHashFunc<K1_>,
100  typename Hash2_ = DefHashFunc<K2_> >
102 {
103 public:
105 
106  HashFuncTuple(const Hash1_ &hash1, const Hash2_ &hash2)
107  : m_hash1(hash1), m_hash2(hash2) { }
108 
109  size_t hash(const Tuple2<K1_,K2_> &key) const {
110  return 23*m_hash1.hash(key.x1()) + 443*m_hash2.hash(key.x2());
111  }
112 
113 private:
114  Hash1_ m_hash1;
115  Hash2_ m_hash2;
116 };
117 
118 }
ogdf::Tuple2::operator=
Tuple2 & operator=(const Tuple2< E1, E2 > &)=default
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::HashFuncTuple::HashFuncTuple
HashFuncTuple(const Hash1_ &hash1, const Hash2_ &hash2)
Definition: tuples.h:106
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:104
ogdf::operator==
bool operator==(const Tuple2< E1, E2 > &t1, const Tuple2< E1, E2 > &t2)
Equality operator for 2-tuples.
Definition: tuples.h:76
ogdf::Tuple2::Tuple2
Tuple2()
Constructs a 2-tuple using default constructors.
Definition: tuples.h:52
OGDF_NEW_DELETE
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
Definition: memory.h:84
ogdf::HashFuncTuple
Definition: tuples.h:101
ogdf::HashFuncTuple::m_hash2
Hash2_ m_hash2
Definition: tuples.h:115
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:54
ogdf::operator<<
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition: Array.h:949
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:114
basic.h
Basic declarations, included by all source files.
ogdf::Tuple2::Tuple2
Tuple2(const Tuple2< E1, E2 > &t2)
Constructs a 2-tuple that is a copy of t2.
Definition: tuples.h:56
ogdf::Tuple2::x2
E2 & x2()
Returns a reference the second element.
Definition: tuples.h:66
ogdf::Tuple2::x1
const E1 & x1() const
Returns a reference the first element.
Definition: tuples.h:59
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:109