Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

HashArray.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/Hashing.h>
35 
36 
37 namespace ogdf {
38 
39 
41 
93 template<class I, class E, class H = DefHashFunc<I> >
94 class HashArray : private Hashing<I,E,H>
95 {
97 
98 public:
101 
103  HashArray() : Hashing<I,E,H>() { }
104 
106  explicit HashArray(const E &defaultValue, const H &hashFunc = H())
107  : Hashing<I,E,H>(256, hashFunc), m_defaultValue(defaultValue) { }
108 
110  HashArray(const HashArray<I,E,H> &A) : Hashing<I,E,H>(A), m_defaultValue(A.m_defaultValue) { }
111 
114 
116  int size() const { return Hashing<I,E,H>::size(); }
117 
119  int empty() const { return Hashing<I,E,H>::empty(); }
120 
121 
123  const E &operator[](const I &i) const {
125  if (pElement) return pElement->info();
126  else return m_defaultValue;
127  }
128 
130  E &operator[](const I &i) {
132  if (!pElement) pElement = Hashing<I,E,H>::fastInsert(i,m_defaultValue);
133  return pElement->info();
134  }
135 
137  bool isDefined(const I &i) const {
138  return Hashing<I,E,H>::member(i);
139  }
140 
142  void undefine(const I &i) {
144  }
145 
148  m_defaultValue = A.m_defaultValue;
150  return *this;
151  }
152 
155 };
156 
157 }
HashElement< K, I > * lookup(const K &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 K &key) const
Returns true iff the hash table contains an element with key key.
Definition: Hashing.h:290
bool empty() const
Returns true iff the table is empty, i.e., contains no elements.
Definition: Hashing.h:287
Indexed arrays using hashing for element access.
Definition: HashArray.h:94
const I & info() const
Returns the information value.
Definition: Hashing.h:199
Declaration of classes used for hashing.
int size() const
Returns the number of elements in the hash table.
Definition: Hashing.h:284
bool isDefined(const I &i) const
Returns true iff index i is defined.
Definition: HashArray.h:137
const E & operator[](const I &i) const
Returns the element with index i.
Definition: HashArray.h:123
int size() const
Returns the number of defined indices (= number of elements in hash table).
Definition: HashArray.h:116
HashConstIterator< K, I, H > begin() const
Returns an hash iterator to the first element in the list of all elements.
Definition: Hashing.h:486
HashArray(const E &defaultValue, const H &hashFunc=H())
Creates a hashing array with default value defaultValue.
Definition: HashArray.h:106
void clear()
Undefines all indices.
Definition: HashArray.h:154
Iterators for hash tables.
Definition: Hashing.h:208
void undefine(const I &i)
Undefines index i.
Definition: HashArray.h:142
Representation of elements in a hash table.
Definition: Hashing.h:180
HashArray(const HashArray< I, E, H > &A)
Copy constructor.
Definition: HashArray.h:110
Hashing< K, I, H > & operator=(const Hashing< K, I, H > &hashing)=default
Assignment operator.
HashArray< I, E, H > & operator=(const HashArray< I, E, H > &A)
Assignment operator.
Definition: HashArray.h:147
HashElement< K, I > * fastInsert(const K &key, const I &info)
Inserts a new element with key key and information info into the hash table.
Definition: Hashing.h:349
HashConstIterator< I, E, H > begin() const
Returns an iterator to the first element in the list of all elements.
Definition: HashArray.h:113
Hashing with chaining and table doubling.
Definition: Hashing.h:264
The namespace for all OGDF objects.
void clear()
Removes all elements from the hash table.
Definition: Hashing.h:365
HashArray()
Creates a hashing array; the default value is the default value of the element type.
Definition: HashArray.h:103
E & operator[](const I &i)
Returns a reference to the element with index i.
Definition: HashArray.h:130
int empty() const
Returns if any indices are defined (= if the hash table is empty)
Definition: HashArray.h:119
void del(const K &key)
Removes the element with key key from the hash table (does nothing if no such element).
Definition: Hashing.h:356