Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

HashArray2D.h
Go to the documentation of this file.
1 
36 #pragma once
37 
39 #include <ogdf/basic/Hashing.h>
40 #include <ogdf/basic/tuples.h>
41 
42 namespace ogdf {
43 
44 
46 
58 template<class I1, class I2, class E, class H1 = DefHashFunc<I1>, class H2 = DefHashFunc<I2>>
59 class HashArray2D : private Hashing<Tuple2<I1, I2>, E, HashFuncTuple<I1, I2, H1, H2>> {
60 public:
63 
66 
68  explicit HashArray2D(const E& defaultValue, const H1& hashFunc1 = H1(),
69  const H2& hashFunc2 = H2())
70  : Hashing<Tuple2<I1, I2>, E, HashFuncTuple<I1, I2, H1, H2>>(256,
71  HashFuncTuple<I1, I2, H1, H2>(hashFunc1, hashFunc2))
72  , m_defaultValue(defaultValue) { }
73 
76  : Hashing<Tuple2<I1, I2>, E, HashFuncTuple<I1, I2, H1, H2>>(A)
78 
81  m_defaultValue = A.m_defaultValue;
83 
84  return *this;
85  }
86 
88 
90  const E& operator()(const I1& i, const I2& j) const {
91  HashElement<Tuple2<I1, I2>, E>* pElement =
93  Tuple2<I1, I2>(i, j));
94  return (pElement) ? pElement->info() : m_defaultValue;
95  }
96 
98  E& operator()(const I1& i, const I2& j) {
99  Tuple2<I1, I2> t(i, j);
100  HashElement<Tuple2<I1, I2>, E>* pElement =
102  if (!pElement) {
105  }
106  return pElement->info();
107  }
108 
110  bool isDefined(const I1& i, const I2& j) const {
112  Tuple2<I1, I2>(i, j));
113  }
114 
116  void undefine(const I1& i, const I2& j) {
118  }
119 
124  }
125 
128 
131 
134 
135 private:
137 };
138 
139 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::HashConstIterator2D
Const-iterator for 2D-hash arrays.
Definition: HashIterator2D.h:47
ogdf::Hashing< Tuple2< I1, I2 >, E, HashFuncTuple< I1, I2, DefHashFunc< I1 >, DefHashFunc< I2 > > >::fastInsert
HashElement< Tuple2< I1, I2 >, E > * fastInsert(const Tuple2< I1, I2 > &key, const E &info)
Inserts a new element with key key and information info into the hash table.
Definition: Hashing.h:351
Hashing.h
Declaration of classes used for hashing.
ogdf::HashArray2D
Indexed 2-dimensional arrays using hashing for element access.
Definition: HashArray2D.h:59
ogdf::Tuple2
Tuples of two elements (2-tuples).
Definition: tuples.h:49
ogdf::HashArray2D::begin
HashConstIterator2D< I1, I2, E, H1, H2 > begin() const
Returns an iterator pointing to the first element.
Definition: HashArray2D.h:121
ogdf::whaType::A
@ A
ogdf::Hashing
Hashing with chaining and table doubling.
Definition: Hashing.h:264
ogdf::HashArray2D::m_defaultValue
E m_defaultValue
The default value of the array.
Definition: HashArray2D.h:136
ogdf::HashArray2D::HashArray2D
HashArray2D(const E &defaultValue, const H1 &hashFunc1=H1(), const H2 &hashFunc2=H2())
Creates a 2D-hash array and sets the default value to defaultValue.
Definition: HashArray2D.h:68
ogdf::HashArray2D::operator=
HashArray2D & operator=(const HashArray2D< I1, I2, E, H1, H2 > &A)
Assignment operator.
Definition: HashArray2D.h:80
ogdf::HashArray2D::clear
void clear()
Undefines all indices.
Definition: HashArray2D.h:133
ogdf::HashFuncTuple
Definition: tuples.h:95
ogdf::HashArray2D::undefine
void undefine(const I1 &i, const I2 &j)
Undefines the entry at index (i,j).
Definition: HashArray2D.h:116
ogdf::HashArray2D::HashArray2D
HashArray2D()
Creates a 2D-hash array.
Definition: HashArray2D.h:65
HashIterator2D.h
Declaration of class HashIterator2D.
ogdf::HashArray2D::operator()
E & operator()(const I1 &i, const I2 &j)
Returns a reference to entry (i,j).
Definition: HashArray2D.h:98
ogdf::HashArray2D::empty
int empty() const
Returns if any indices are defined.
Definition: HashArray2D.h:130
ogdf::HashArray2D::operator()
const E & operator()(const I1 &i, const I2 &j) const
Returns a const reference to entry (i,j).
Definition: HashArray2D.h:90
ogdf::Hashing< Tuple2< I1, I2 >, E, HashFuncTuple< I1, I2, DefHashFunc< I1 >, DefHashFunc< I2 > > >::del
void del(const Tuple2< I1, I2 > &key)
Removes the element with key key from the hash table (does nothing if no such element).
Definition: Hashing.h:358
ogdf::Hashing< Tuple2< I1, I2 >, E, HashFuncTuple< I1, I2, DefHashFunc< I1 >, DefHashFunc< I2 > > >::lookup
HashElement< Tuple2< I1, I2 >, E > * lookup(const Tuple2< I1, I2 > &key) const
Returns the hash element with key key in the hash table; returns nullptr if no such element exists.
Definition: Hashing.h:295
ogdf::Hashing< Tuple2< I1, I2 >, E, HashFuncTuple< I1, I2, DefHashFunc< I1 >, DefHashFunc< I2 > > >::member
bool member(const Tuple2< I1, I2 > &key) const
Returns true iff the hash table contains an element with key key.
Definition: Hashing.h:289
ogdf::HashArray2D::HashArray2D
HashArray2D(const HashArray2D< I1, I2, E, H1, H2 > &A)
Copy constructor.
Definition: HashArray2D.h:75
ogdf::HashArray2D::size
int size() const
Returns the number of defined elements in the table.
Definition: HashArray2D.h:127
ogdf::HashElement
Representation of elements in a hash table.
Definition: Hashing.h:179
ogdf::HashElement::info
const I & info() const
Returns the information value.
Definition: Hashing.h:195
ogdf::HashArray2D::~HashArray2D
~HashArray2D()
Definition: HashArray2D.h:87
tuples.h
Declaration and implementation of class Tuple2, Tuple3 and Tuple4.
ogdf::HashArray2D::isDefined
bool isDefined(const I1 &i, const I2 &j) const
Returns true iff entry (i,j) is defined.
Definition: HashArray2D.h:110