Hashing with chaining and table doubling. More...
#include <ogdf/basic/Hashing.h>
Public Types | |
using | const_iterator = HashConstIterator< K, I, H > |
The type of const-iterators for hash tables. | |
Public Member Functions | |
Hashing (const Hashing< K, I, H > &h)=default | |
Copy constructor. | |
Hashing (int minTableSize=256, const H &hashFunc=H()) | |
Creates a hash table for given initial table size minTableSize . | |
~Hashing () | |
Destruction. | |
HashConstIterator< K, I, H > | begin () const |
Returns an hash iterator to the first element in the list of all elements. | |
void | clear () |
Removes all elements from the hash table. | |
void | del (const K &key) |
Removes the element with key key from the hash table (does nothing if no such element). | |
bool | empty () const |
Returns true iff the table is empty, i.e., contains no elements. | |
HashElement< K, I > * | fastInsert (const K &key, const I &info) |
Inserts a new element with key key and information info into the hash table. | |
HashElement< K, I > * | insert (const K &key, const I &info) |
Inserts a new element with key key and information info into the hash table. | |
HashElement< K, I > * | insertByNeed (const K &key, const I &info) |
Inserts a new element with key key and information info into the hash table. | |
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. | |
bool | member (const K &key) const |
Returns true iff the hash table contains an element with key key . | |
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. | |
Protected Member Functions | |
HashElement< K, I > * | firstElement (HashElement< K, I > ***pList) const |
Returns the first element in the list of all elements in the hash table. | |
HashElement< K, I > * | nextElement (HashElement< K, I > ***pList, HashElement< K, I > *pElement) const |
Returns the successor of pElement in the list of all elements in the hash table. | |
Private Member Functions | |
virtual HashElementBase * | copy (HashElementBase *pElement) const override |
Returns a copy of hash element pElement . | |
virtual void | destroy (HashElementBase *pElement) override |
Deletes hash element pElement . | |
Private Member Functions inherited from ogdf::HashingBase | |
HashingBase (const HashingBase &H) | |
Copy constructor. | |
HashingBase (int minTableSize) | |
Creates a hash table with minimum table size minTableSize . | |
virtual | ~HashingBase () |
Destruction. | |
void | clear () |
Removes all elements from the hash table. | |
void | del (HashElementBase *pElement) |
Removes the element pElement from the hash table. | |
int | empty () const |
Returns if the hash table is empty. | |
HashElementBase * | firstElement (HashElementBase ***pList) const |
Returns the first element in the list of all elements in the hash table. | |
HashElementBase * | firstListElement (size_t hashValue) const |
Returns the first element in the list for elements with hash value hashValue . | |
void | insert (HashElementBase *pElement) |
Inserts a new element pElement into the hash table. | |
HashElementBase * | nextElement (HashElementBase ***pList, HashElementBase *pElement) const |
Returns the successor of pElement in the list of all elements in the hash table. | |
HashingBase & | operator= (const HashingBase &H) |
Assignment operator. | |
void | resize (int newTableSize) |
Resizes the hash table to newTableSize . | |
int | size () const |
Returns the number of elements in the hash table. | |
void | destroyAll () |
Deletes all elements in hash table (but does not free m_table!). | |
Private Attributes | |
H | m_hashFunc |
The hash function. | |
Private Attributes inherited from ogdf::HashingBase | |
int | m_count |
The current number of elements. | |
int | m_hashMask |
The current table size minus one. | |
int | m_minTableSize |
The minimal table size. | |
HashElementBase ** | m_table |
The hash table (an array of lists). | |
int | m_tableSize |
The current table size. | |
int | m_tableSizeHigh |
The maximal number of elements at this table size. | |
int | m_tableSizeLow |
The minimal number of elements at this table size. | |
Friends | |
class | HashConstIterator< K, I, H > |
Hashing with chaining and table doubling.
The class Hashing<K,I> implements a hashing table which realizes a mapping from a key type K to an information type I.
The class requires three template parameters:
K | is the type of keys. |
I | is the type of information. |
H | is the hash function type. The hash function type argument is optional; its default uses the class DefHashFunc. |
Hash function classes have to define int hash(const E &key)
or int hash(E key)
.
using ogdf::Hashing< K, I, H >::const_iterator = HashConstIterator<K, I, H> |
|
inline |
|
inline |
|
inline |
|
inlineoverrideprivatevirtual |
Returns a copy of hash element pElement
.
Implements ogdf::HashingBase.
|
inlineoverrideprivatevirtual |
Deletes hash element pElement
.
Implements ogdf::HashingBase.
|
inline |
|
inline |
|
inlineprotected |
Returns the first element in the list of all elements in the hash table.
This function is used by hash iterators for iterating over all elements in the hash table.
pList | is assigned the list containing the first element. |
nullptr
if hash table is empty.
|
inline |
|
inline |
|
inline |
|
inlineprotected |
Returns the successor of pElement
in the list of all elements in the hash table.
This function is used by hash iterators for iterating over all elements in the hash table.
pList | is assigned the list containing the first element. |
pElement | points to an element in the has table. |
nullptr
if hash table is empty.
|
default |
Assignment operator.
|
inline |
|
friend |
|
private |