34template <
class KeyType,
class ItemType>
44template <
class KeyType,
class ItemType>
47 return out <<
'(' << rhs.key_ <<
',' << rhs.item_ <<
')';
51template <
class KeyType,
class ItemType>
59template <
class KeyType,
class ItemType>
60AbaHash<KeyType, ItemType>::AbaHash(
int size)
65 for (
int i = 0; i <
size; i++)
70template <
class KeyType,
class ItemType>
71AbaHash<KeyType, ItemType>::~AbaHash()
77 for (i = 0; i < size_; i++) {
89template <
class KeyType,
class ItemType>
90std::ostream &
operator<<(std::ostream &out,
const AbaHash<KeyType, ItemType> &hash)
93 const int s = hash.size();
95 for (
int i = 0; i < s; i++) {
110template <
class KeyType,
class ItemType>
111void AbaHash<KeyType, ItemType>::insert(
118 if (table_[
slotNum]) ++nCollisions_;
124template <
class KeyType,
class ItemType>
125void AbaHash<KeyType, ItemType>::overWrite(
131 if (table_[
slotNum]) ++nCollisions_;
139 if (
h->key_ == key) {
153template <
class KeyType,
class ItemType>
154const ItemType * AbaHash<KeyType, ItemType>::find(
const KeyType &key)
const
158 slot = table_[hf(key)];
161 if (key == slot->key_)
return &(slot->item_);
167template <
class KeyType,
class ItemType>
172 slot = table_[hf(key)];
175 if (key == slot->key_)
return &(slot->item_);
181template <
class KeyType,
class ItemType>
182bool AbaHash<KeyType, ItemType>::find (
const KeyType &key,
const ItemType &item)
const
186 slot = table_[hf(key)];
189 if (key == slot->key_ && slot->item_ == item)
197template <
class KeyType,
class ItemType>
198ItemType *AbaHash<KeyType, ItemType>::initializeIteration(
const KeyType &key)
200 iter_ = table_[hf(key)];
202 if (key == iter_->key_)
return &(iter_->item_);
203 iter_ = iter_->next_;
208template <
class KeyType,
class ItemType>
209const ItemType *AbaHash<KeyType, ItemType>::initializeIteration(
const KeyType &key)
const
211 iter_ = table_[hf(key)];
213 if (key == iter_->key_)
return &(iter_->item_);
214 iter_ = iter_->next_;
219template <
class KeyType,
class ItemType>
222 if (iter_ ==
nullptr)
return nullptr;
223 iter_ = iter_->next_;
226 if (key == iter_->key_)
return &(iter_->item_);
227 iter_ = iter_->next();
232template <
class KeyType,
class ItemType>
233const ItemType *AbaHash<KeyType, ItemType>::next(
const KeyType &key)
const
235 if (iter_ ==
nullptr)
return nullptr;
236 iter_ = iter_->next_;
239 if (key == iter_->key_)
return &(iter_->item_);
240 iter_ = iter_->next();
245template <
class KeyType,
class ItemType>
246int AbaHash<KeyType, ItemType>::remove(
const KeyType &key)
258 if (
h1->key_ == key) {
265 while ((
h2 =
h1->next_)) {
266 if (
h2->key_ == key) {
267 h1->next_ =
h2->next_;
277template <
class KeyType,
class ItemType>
278int AbaHash<KeyType, ItemType>::remove(
const KeyType &key,
const ItemType &item)
290 if (
h1->key_ == key &&
h1->item_ == item) {
297 while ((
h2 =
h1->next_)) {
298 if (
h2->key_ == key &&
h2->item_ == item) {
299 h1->next_ =
h2->next_;
309template <
class KeyType,
class ItemType>
310inline int AbaHash<KeyType, ItemType>::size()
const
316template <
class KeyType,
class ItemType>
317inline int AbaHash<KeyType, ItemType>::nCollisions()
const
323template <
class KeyType,
class ItemType>
324inline int AbaHash<KeyType, ItemType>::hf(
int key)
const
326 if (key < 0) key = -key;
328 double x = key*0.6180339887;
334template <
class KeyType,
class ItemType>
335inline int AbaHash<KeyType, ItemType>::hf(
unsigned key)
const
337 double x = key*0.6180339887;
343template <
class KeyType,
class ItemType>
344int AbaHash<KeyType, ItemType>::hf(
const string &
str)
const
346 const int prime = 516595003;
347 const int mult = 314159;
349 string::size_type s =
str.size();
351 for (string::size_type i = 0; i < s; i++) {
361template <
class KeyType,
class ItemType>
362void AbaHash<KeyType, ItemType>::resize(
int newSize)
366 Logger::ifout() <<
"AbaHash::resize(): new size of hash table must be positive.\n";
378 for (
int i = 0; i <
newSize; i++)
392 for (
int i = 0; i <
oldSize; i++) {
AbaHashItem(const KeyType &key, const ItemType &item)
The constructor.
#define OGDF_THROW_PARAM(CLASS, PARAM)
Replacement for throw.
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.