Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
hash.h
Go to the documentation of this file.
1
30#pragma once
31
33
34#pragma GCC visibility push(default)
35namespace abacus {
36
37class AbacusGlobal;
38
39template<class KeyType,class ItemType> class AbaHash;
40
41template <class KeyType, class ItemType>
42class AbaHashItem;
43template <class KeyType, class ItemType>
44class AbaHash;
45
46template <class KeyType, class ItemType>
47std::ostream &operator<< (std::ostream &out, const AbaHashItem<KeyType, ItemType> &rhs);
48
49template <class KeyType, class ItemType>
50std::ostream &operator<< (std::ostream &out, const AbaHash<KeyType, ItemType> &hash);
51
52
54/*
55 * \sa AbaHash
56 */
57template <class KeyType, class ItemType>
58class AbaHashItem : public AbacusRoot {
59 friend class AbaHash<KeyType, ItemType>;
60
61public:
62
64
68 AbaHashItem(const KeyType &key, const ItemType &item);
69
70
72
75 friend std::ostream &operator<< <> (std::ostream &,
77
80
83
84private:
85 KeyType key_;
86 ItemType item_;
88
90};
91
92
94
124template <class KeyType, class ItemType>
125class AbaHash : public AbacusRoot {
126public:
127
129
132 explicit AbaHash(int size);
133
135
139
141
152 friend std::ostream &operator<< <> (std::ostream &out,
153 const AbaHash<KeyType, ItemType> &hash);
154
156
164 void insert(const KeyType &newKey, const ItemType &newItem);
165
167
174 void overWrite(const KeyType &newKey, const ItemType &newItem);
175
177
185 const ItemType *find(const KeyType &key) const;
186
188
196 ItemType *find(const KeyType &key);
197
199
205 bool find(const KeyType &key, const ItemType &item) const;
206
212
214
220 ItemType *initializeIteration(const KeyType &key);
221
223
229 const ItemType *initializeIteration(const KeyType &key) const;
230
232
244 ItemType *next(const KeyType &key);
245
247
259 const ItemType *next(const KeyType &key) const;
261
263
269 int remove(const KeyType &key);
270
272
279 int remove(const KeyType &key, const ItemType &item);
280
282 int size() const;
283
285 int nCollisions() const;
286
288
291 void resize(int newSize);
292
293 private:
294
296
302 int hf(int key) const;
303
305 int hf(unsigned key) const;
306
308
311 int hf(const string &str) const;
312
313
315
321
323 int size_;
324
327
329
334
335 AbaHash(const AbaHash &rhs);
337};
338
339}
340
342#pragma GCC visibility pop
Hash tables.
Definition hash.h:125
int nCollisions_
The number of collisions on calls of insert() and overWrite().
Definition hash.h:326
bool find(const KeyType &key, const ItemType &item) const
Checks if a prespecified item with a prespecified key is contained in the hash table.
int remove(const KeyType &key)
Removes the first item with a given key from the hash table.
int size_
The length of the hash table.
Definition hash.h:323
int hf(unsigned key) const
This version of hf() implements a Fibonacci hash function for keys of type unsigned.
AbaHashItem< KeyType, ItemType > ** table_
The hash table storing a linked list of hash items in each slot.
Definition hash.h:320
int nCollisions() const
Returns the number of collisions which occurred during all previous calls of the functions insert() a...
ItemType * find(const KeyType &key)
Looks for an item in the hash table with a given key.
const ItemType * find(const KeyType &key) const
Looks for an item in the hash table with a given key.
const ItemType * next(const KeyType &key) const
This function can be used to go to the next item in the hash table with key key.
const ItemType * initializeIteration(const KeyType &key) const
This function retrieves the first item.
void insert(const KeyType &newKey, const ItemType &newItem)
Adds an item to the hash table.
ItemType * initializeIteration(const KeyType &key)
This function retrieves the first item.
AbaHash(const AbaHash &rhs)
AbaHash(int size)
Initializes each slot with a 0-pointer to indicate that the linked list of hash items of this slot is...
int hf(const string &str) const
This is a hash function for character strings.
int remove(const KeyType &key, const ItemType &item)
Removes the first item with a given key and a prespecified element from the hash table.
AbaHash & operator=(const AbaHash &rhs)
int hf(int key) const
Computes the hash value of key.
ItemType * next(const KeyType &key)
This function can be used to go to the next item in the hash table with key key.
AbaHashItem< KeyType, ItemType > * iter_
An iterator for all items stored in a slot.
Definition hash.h:333
void overWrite(const KeyType &newKey, const ItemType &newItem)
Adds a item to the has table (with overwrite).
int size() const
Returns the length of the hash table.
void resize(int newSize)
Can be used to change the size of the hash table.
~AbaHash()
The destructor.
Items in hash tables.
Definition hash.h:58
ItemType item_
Definition hash.h:86
KeyType key_
Definition hash.h:85
AbaHashItem< KeyType, ItemType > * next_
Definition hash.h:87
AbaHashItem(const KeyType &key, const ItemType &item)
The constructor.
const AbaHashItem< KeyType, ItemType > * next() const
Returns a const pointer to the next hash-item stored in the linked list corresponding to the slot of ...
AbaHashItem< KeyType, ItemType > * next()
Returns a pointer to the next hash-item stored in the linked list corresponding to the slot of this i...
Base class of all other classes of ABACUS.
Definition abacusroot.h:69
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
Definition memory.h:85
std::ostream & operator<<(std::ostream &out, const Active< BaseType, CoType > &rhs)