Indexed arrays using hashing for element access. More...
#include <ogdf/basic/HashArray.h>
Inheritance diagram for ogdf::HashArray< I, E, H >:Public Types | |
| typedef HashConstIterator< I, E, H > | const_iterator |
| The default value for elements. | |
Public Member Functions | |
| HashArray () | |
| Creates a hashing array; the default value is the default value of the element type. | |
| HashArray (const E &defaultValue, const H &hashFunc=H()) | |
| Creates a hashing array with default value defaultValue. | |
| HashArray (const HashArray< I, E, H > &A) | |
| Copy constructor. | |
| HashConstIterator< I, E, H > | begin () const |
| Returns an iterator to the first element in the list of all elements. | |
| void | clear () |
| Undefines all indices. | |
| int | empty () const |
| Returns if any indices are defined (= if the hash table is empty) | |
| bool | isDefined (const I &i) const |
| Returns true iff index i is defined. | |
| HashArray< I, E, H > & | operator= (const HashArray< I, E, H > &A) |
| Assignment operator. | |
| const E & | operator[] (const I &i) const |
| Returns the element with index i. | |
| E & | operator[] (const I &i) |
| Returns a reference to the element with index i. | |
| int | size () const |
| Returns the number of defined indices (= number of elements in hash table). | |
| void | undefine (const I &i) |
| Undefines index i. | |
Private Attributes | |
| E | m_defaultValue |
Additional Inherited Members | |
Private Types inherited from ogdf::Hashing< I, E, H > | |
Private Member Functions inherited from ogdf::Hashing< I, E, H > | |
| Hashing (int minTableSize=256, const H &hashFunc=H()) | |
| Creates a hash table for given initial table size minTableSize. | |
| Hashing (const Hashing< I, E > &h) | |
| Copy constructor. | |
| ~Hashing () | |
| void | del (const I &key) |
| Removes the element with key key from the hash table (does nothing if no such element). | |
| HashElement< I, E > * | fastInsert (const I &key, const E &info) |
| Inserts a new element with key key and information info into the hash table. | |
| HashElement< I, E > * | insert (const I &key, const E &info) |
| Inserts a new element with key key and information info into the hash table. | |
| HashElement< I, E > * | insertByNeed (const I &key, const E &info) |
| Inserts a new element with key key and information info into the hash table. | |
| HashElement< I, E > * | lookup (const I &key) const |
| Returns the hash element with key key in the hash table; returns 0 if no such element. | |
| bool | member (const I &key) const |
| Returns true iff the hash table contains an element with key key. | |
| Hashing< I, E > & | operator= (const Hashing< I, E > &hashing) |
| Assignment operator. | |
| HashElement< I, E > * | firstElement (HashElement< I, E > ***pList) const |
| Returns the first element in the list of all elements in the hash table. | |
| HashElement< I, E > * | nextElement (HashElement< I, E > ***pList, HashElement< I, E > *pElement) const |
| Returns the successor of pElement in the list of all elements in the hash table. | |
Indexed arrays using hashing for element access.
| I | is the index type. |
| E | is the element type. |
| H | is the hash function type. Optional; its default uses the class DefHashFunc. |
A hashing array can be used like a usual array but has a general index type.
The hashing array is only defined for a subset Idef of the index set (set of all elements of the index type). At construction, this set is empty. Whenever an index is assigned an element, this index is added to Idef. There are also method for testing if an index is defined (is in Idef).
The following code snippet demonstrates how to use a hashing array. First, the example inserts elements into a hashing array simulating a tiny German–English dictionary, then it prints some elements via array access, and finally it iterates over all defined indices and prints the dictionary entries. We use a the const reference Hc, since we want to avoid that array access for undefined indices creates these elements.
The produced output is as follows:
Definition at line 110 of file HashArray.h.
| typedef HashConstIterator<I,E,H> ogdf::HashArray< I, E, H >::const_iterator |
The default value for elements.
The type of const-iterators for hash arrays.
Reimplemented from ogdf::Hashing< I, E, H >.
Definition at line 116 of file HashArray.h.
|
inline |
Creates a hashing array; the default value is the default value of the element type.
Definition at line 119 of file HashArray.h.
|
inline |
Creates a hashing array with default value defaultValue.
Definition at line 122 of file HashArray.h.
|
inline |
Copy constructor.
Definition at line 126 of file HashArray.h.
|
inline |
Returns an iterator to the first element in the list of all elements.
Reimplemented from ogdf::Hashing< I, E, H >.
Definition at line 129 of file HashArray.h.
|
inline |
Undefines all indices.
Reimplemented from ogdf::Hashing< I, E, H >.
Definition at line 170 of file HashArray.h.
|
inline |
Returns if any indices are defined (= if the hash table is empty)
Reimplemented from ogdf::Hashing< I, E, H >.
Definition at line 135 of file HashArray.h.
|
inline |
Returns true iff index i is defined.
Definition at line 153 of file HashArray.h.
|
inline |
Assignment operator.
Definition at line 163 of file HashArray.h.
|
inline |
Returns the element with index i.
Definition at line 139 of file HashArray.h.
|
inline |
Returns a reference to the element with index i.
Definition at line 146 of file HashArray.h.
|
inline |
Returns the number of defined indices (= number of elements in hash table).
Reimplemented from ogdf::Hashing< I, E, H >.
Definition at line 132 of file HashArray.h.
|
inline |
Undefines index i.
Definition at line 158 of file HashArray.h.
|
private |
Definition at line 112 of file HashArray.h.