Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
HashArray.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <ogdf/basic/Hashing.h>
35
36namespace ogdf {
37
38
40
92template<class I, class E, class H = DefHashFunc<I>>
93class HashArray : private Hashing<I, E, H> {
95
96public:
99
101 HashArray() : Hashing<I, E, H>() { }
102
104 explicit HashArray(const E& defaultValue, const H& hashFunc = H())
105 : Hashing<I, E, H>(256, hashFunc), m_defaultValue(defaultValue) { }
106
110
113
115 int size() const { return Hashing<I, E, H>::size(); }
116
118 int empty() const { return Hashing<I, E, H>::empty(); }
119
121 const E& operator[](const I& i) const {
123 if (pElement) {
124 return pElement->info();
125 } else {
126 return m_defaultValue;
127 }
128 }
129
131 E& operator[](const I& i) {
133 if (!pElement) {
135 }
136 return pElement->info();
137 }
138
140 bool isDefined(const I& i) const { return Hashing<I, E, H>::member(i); }
141
143 void undefine(const I& i) { Hashing<I, E, H>::del(i); }
144
147 m_defaultValue = A.m_defaultValue;
149 return *this;
150 }
151
154};
155
156}
Declaration of classes used for hashing.
Indexed arrays using hashing for element access.
Definition HashArray.h:93
HashArray(const E &defaultValue, const H &hashFunc=H())
Creates a hashing array with default value defaultValue.
Definition HashArray.h:104
HashArray< I, E, H > & operator=(const HashArray< I, E, H > &A)
Assignment operator.
Definition HashArray.h:146
int empty() const
Returns if any indices are defined (= if the hash table is empty)
Definition HashArray.h:118
int size() const
Returns the number of defined indices (= number of elements in hash table).
Definition HashArray.h:115
const E & operator[](const I &i) const
Returns the element with index i.
Definition HashArray.h:121
HashConstIterator< I, E, H > begin() const
Returns an iterator to the first element in the list of all elements.
Definition HashArray.h:112
HashArray(const HashArray< I, E, H > &A)
Copy constructor.
Definition HashArray.h:108
void clear()
Undefines all indices.
Definition HashArray.h:153
bool isDefined(const I &i) const
Returns true iff index i is defined.
Definition HashArray.h:140
void undefine(const I &i)
Undefines index i.
Definition HashArray.h:143
E & operator[](const I &i)
Returns a reference to the element with index i.
Definition HashArray.h:131
HashArray()
Creates a hashing array; the default value is the default value of the element type.
Definition HashArray.h:101
Iterators for hash tables.
Definition Hashing.h:429
Representation of elements in a hash table.
Definition Hashing.h:176
Hashing with chaining and table doubling.
Definition Hashing.h:261
void del(const K &key)
Removes the element with key key from the hash table (does nothing if no such element).
Definition Hashing.h:355
HashConstIterator< K, I, H > begin() const
Returns an hash iterator to the first element in the list of all elements.
Definition Hashing.h:484
void clear()
Removes all elements from the hash table.
Definition Hashing.h:364
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:348
bool empty() const
Returns true iff the table is empty, i.e., contains no elements.
Definition Hashing.h:283
Hashing< K, I, H > & operator=(const Hashing< K, I, H > &hashing)=default
Assignment operator.
int size() const
Returns the number of elements in the hash table.
Definition Hashing.h:280
bool member(const K &key) const
Returns true iff the hash table contains an element with key key.
Definition Hashing.h:286
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:292
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.