58 explicit HashElementBase(
size_t hashValue) : m_next(nullptr), m_hashValue(hashValue) { }
97 void resize(
int newTableSize);
112 int size()
const {
return m_count; }
115 int empty()
const {
return m_count==0; }
123 return *(m_table + (hashValue & m_hashMask));
165 void init(
int tableSize);
179 template<
class K,
class I>
196 const K &
key()
const {
return m_key; }
199 const I &
info()
const {
return m_info; }
221 size_t hash(
const K &key)
const {
return size_t(key); }
227 size_t hash(
const void * &key)
const {
return size_t(key && 0xffffffff); }
233 size_t hash(
const double &key)
const {
235 return (
size_t)((double)numeric_limits<size_t>::max() * frexp(key,&dummy));
242 size_t hash(
const string &key)
const;
263 template<
class K,
class I,
class H = DefHashFunc<K> >
274 explicit Hashing(
int minTableSize = 256,
const H &hashFunc =
H())
275 :
HashingBase(minTableSize), m_hashFunc(hashFunc) { }
290 bool member(
const K &key)
const {
return lookup(key) !=
nullptr; }
299 for (; pElement; pElement = pElement->
next())
300 if (pElement->
key() == key)
return pElement;
323 pElement->
info() = info;
437 template<
class K,
class I,
class H = DefHashFunc<K> >
449 const Hashing<K,I,H> *pHashing) : m_pElement(pElement), m_pList(pList),
450 m_pHashing(pHashing) { }
454 m_pList(it.m_pList), m_pHashing(it.m_pHashing) { }
465 bool valid()
const {
return m_pElement !=
nullptr; }
468 const K &
key()
const {
return m_pElement->
key(); }
471 const I &
info()
const {
return m_pElement->
info(); }
483 m_pElement = m_pHashing->
nextElement(&m_pList,m_pElement);
489 template<
class K,
class I,
class H>
493 pElement = firstElement(&pList);
HashElement< K, I > * lookup(const K &key) const
Returns the hash element with key key in the hash table; returns 0 if no such element.
HashElement< K, I > * next() const
Returns the successor element in the list.
HashElement< K, I > * m_pElement
The hash element to which the iterator points.
bool member(const K &key) const
Returns true iff the hash table contains an element with key key.
HashElement< K, I > * insert(const K &key, const I &info)
Inserts a new element with key key and information info into the hash table.
I & info()
Returns a refeence to the information value.
const K & key() const
Returns the key of the hash element pointed to.
HashElementBase * nextElement(HashElementBase ***pList, HashElementBase *pElement) const
Returns the successor of pElement in the list of all elements in the hash table.
Declaration of memory manager for allocating small pieces of memory.
HashConstIterator(const HashConstIterator< K, I, H > &it)
Copy constructor.
HashingBase & operator=(const HashingBase &H)
Assignment operator.
size_t hashValue() const
Returns the hash value of this element.
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
HashElementBase(size_t hashValue)
Creates a hash element with hash value hashValue.
int m_count
The current number of elements.
bool empty() const
Returns true iff the table is empty, i.e., contains no elements.
const I & info() const
Returns the information of the hash element pointed to.
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.
HashConstIterator & operator=(const HashConstIterator< K, I, H > &it)
Assignment operator.
const I & info() const
Returns the information value.
HashElement< K, I > ** m_pList
The list containg the hash element.
int size() const
Returns the number of elements in the hash table.
int size() const
Returns the number of elements in the hash table.
int empty() const
Returns if the hash table is empty.
Hashing(const Hashing< K, I > &h)
Copy constructor.
void del(HashElementBase *pElement)
Removes the element pElement from the hash table.
HashElementBase * next() const
Returns the successor to this element in the list.
int m_hashMask
The current table size minus one.
const Hashing< K, I, H > * m_pHashing
The associated hash table.
HashConstIterator< K, I, H > & operator++()
Moves this hash iterator to the next element (iterator gets invalid if no more elements).
Base class for hashing with chaining and table doubling.
HashElementBase * firstListElement(size_t hashValue) const
Returns the first element in the list for elements with hash value hashValue.
HashConstIterator< K, I, H > begin() const
Returns an hash iterator to the first element in the list of all elements.
Base class for elements within a hash table.
Iterators for hash tables.
static void copy(const T &from, T &to)
Hashing(int minTableSize=256, const H &hashFunc=H())
Creates a hash table for given initial table size minTableSize.
Hashing< K, I > & operator=(const Hashing< K, I > &hashing)
Assignment operator.
size_t hash(const void *&key) const
I m_info
The information value.
size_t m_hashValue
The hash value.
size_t hash(const double &key) const
H m_hashFunc
The hash function.
friend bool operator!=(const HashConstIterator< K, I, H > &it1, const HashConstIterator< K, I, H > &it2)
Inequality operator.
static uint32_t hash(uint32_t x)
int m_minTableSize
The minimal table size.
Representation of elements in a hash table.
int m_tableSize
The current table size.
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
HashElement< K, I > * insertByNeed(const K &key, const I &info)
Inserts a new element with key key and information info into the hash table.
virtual HashElementBase * copy(HashElementBase *pElement) const override
Returns a copy of hash element pElement.
int m_tableSizeHigh
The maximal number of elements at this table size.
HashElement(size_t hashValue, const K &key, const I &info)
Creates a hash element with given hash value, key, and information.
friend bool operator==(const HashConstIterator< K, I, H > &it1, const HashConstIterator< K, I, H > &it2)
Equality operator.
void insert(HashElementBase *pElement)
Inserts a new element pElement into the hash table.
Basic declarations, included by all source files.
HashElementBase * m_next
The successor in the list.
HashConstIterator(HashElement< K, I > *pElement, HashElement< K, I > **pList, const Hashing< K, I, H > *pHashing)
Creates a hash iterator pointing to element pElement in list pList of hash table pHashing.
HashElement< K, I > * fastInsert(const K &key, const I &info)
Inserts a new element with key key and information info into the hash table.
virtual void destroy(HashElementBase *pElement) override
Deletes hash element pElement.
size_t hash(const K &key) const
Returns the hash value of key.
void destroyAll()
Deletes all elements in hash table (but does not free m_table!).
HashElement< K, I > * firstElement(HashElement< K, I > ***pList) const
Returns the first element in the list of all elements in the hash table.
HashElementBase ** m_table
The hash table (an array of lists).
HashConstIterator()
Creates a hash iterator pointing to no element.
Hashing with chaining and table doubling.
The namespace for all OGDF objects.
HashElementBase * firstElement(HashElementBase ***pList) const
Returns the first element in the list of all elements in the hash table.
void clear()
Removes all elements from the hash table.
void clear()
Removes all elements from the hash table.
const K & key() const
Returns the key value.
bool valid() const
Returns true if the hash iterator points to an element.
void del(const K &key)
Removes the element with key key from the hash table (does nothing if no such element).
int m_tableSizeLow
The minimal number of elements at this table size.