Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

HashArray2D.h
Go to the documentation of this file.
1 
36 #pragma once
37 
38 #include <ogdf/basic/HashArray.h>
39 #include <ogdf/basic/tuples.h>
41 
42 
43 namespace ogdf {
44 
45 
47 
59 template<
60  class I1,
61  class I2,
62  class E,
63  class H1 = DefHashFunc<I1>,
64  class H2 = DefHashFunc<I2> >
65 class HashArray2D : private Hashing< Tuple2<I1,I2>, E, HashFuncTuple<I1,I2,H1,H2> >
66 {
67 public:
70 
73 
75  explicit HashArray2D(const E &defaultValue, const H1 &hashFunc1 = H1(), const H2 &hashFunc2 = H2()) :
76  Hashing<Tuple2<I1,I2>,E,HashFuncTuple<I1,I2,H1,H2> >(
77  256,
78  HashFuncTuple<I1,I2,H1,H2>(hashFunc1,hashFunc2)),
79  m_defaultValue(defaultValue) { }
80 
83  Hashing<Tuple2<I1,I2>,E,HashFuncTuple<I1,I2,H1,H2> >(A),
85 
90 
91  return *this;
92  }
93 
95 
97  const E &operator()(const I1 &i, const I2 &j) const {
98  HashElement<Tuple2<I1,I2>,E> *pElement =
100  return (pElement) ? pElement->info() : m_defaultValue;
101  }
102 
104  E &operator()(const I1 &i, const I2 &j) {
105  Tuple2<I1,I2> t(i,j);
106  HashElement<Tuple2<I1,I2>,E> *pElement =
108  if (!pElement)
110  return pElement->info();
111  }
112 
114  bool isDefined(const I1 &i, const I2 &j) const {
116  }
117 
119  void undefine(const I1 &i, const I2 &j) {
121  }
122 
127  }
128 
130  int size() const {
132  }
133 
135  int empty() const {
137  }
138 
139 
141  void clear() {
143  }
144 
145 private:
147 };
148 
149 }
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:296
bool member(const Tuple2< I1, I2 > &key) const
Returns true iff the hash table contains an element with key key.
Definition: Hashing.h:290
HashArray2D(const HashArray2D< I1, I2, E, H1, H2 > &A)
Copy constructor.
Definition: HashArray2D.h:82
void clear()
Undefines all indices.
Definition: HashArray2D.h:141
Declaration and implementation of HashArray class.
int size() const
Returns the number of defined elements in the table.
Definition: HashArray2D.h:130
Const-iterator for 2D-hash arrays.
const I & info() const
Returns the information value.
Definition: Hashing.h:199
const E & operator()(const I1 &i, const I2 &j) const
Returns a const reference to entry (i,j).
Definition: HashArray2D.h:97
Declaration of class HashIterator2D.
bool isDefined(const I1 &i, const I2 &j) const
Returns true iff entry (i,j) is defined.
Definition: HashArray2D.h:114
Indexed 2-dimensional arrays using hashing for element access.
Definition: HashArray2D.h:65
E m_defaultValue
The default value of the array.
Definition: HashArray2D.h:146
Tuples of two elements (2-tuples).
Definition: tuples.h:46
HashArray2D & operator=(const HashArray2D< I1, I2, E, H1, H2 > &A)
Assignment operator.
Definition: HashArray2D.h:87
Representation of elements in a hash table.
Definition: Hashing.h:180
Declaration and implementation of class Tuple2, Tuple3 and Tuple4.
void undefine(const I1 &i, const I2 &j)
Undefines the entry at index (i,j).
Definition: HashArray2D.h:119
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:349
HashConstIterator2D< I1, I2, E, H1, H2 > begin() const
Returns an iterator pointing to the first element.
Definition: HashArray2D.h:124
HashArray2D()
Creates a 2D-hash array.
Definition: HashArray2D.h:72
int empty() const
Returns if any indices are defined.
Definition: HashArray2D.h:135
Hashing with chaining and table doubling.
Definition: Hashing.h:264
E & operator()(const I1 &i, const I2 &j)
Returns a reference to entry (i,j).
Definition: HashArray2D.h:104
The namespace for all OGDF objects.
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:356
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:75