26 #ifndef StaticHashTable_C
27 #define StaticHashTable_C
44 unsigned int goodSize = size;
46 if (goodSize & (goodSize - 1))
50 while (goodSize <
unsigned(size))
63 template<
class T,
class Key,
class Hash>
68 objects_(keys_.size()),
70 endIter_(*this, keys_.size(), 0),
71 endConstIter_(*this, keys_.size(), 0)
76 <<
"Illegal size " << size <<
" for StaticHashTable."
83 template<
class T,
class Key,
class Hash>
86 const StaticHashTable<T, Key, Hash>& ht
89 StaticHashTableCore(),
91 objects_(ht.objects_),
93 endIter_(*this, keys_.size(), 0),
94 endConstIter_(*this, keys_.size(), 0)
98 template<
class T,
class Key,
class Hash>
101 const Xfer<StaticHashTable<T, Key, Hash> >& ht
104 StaticHashTableCore(),
108 endIter_(*this, 0, 0),
109 endConstIter_(*this, 0, 0)
117 template<
class T,
class Key,
class Hash>
124 template<
class T,
class Key,
class Hash>
129 const label hashIdx = hashKeyIndex(key);
130 const List<Key>& localKeys = keys_[hashIdx];
132 forAll(localKeys, elemIdx)
134 if (key == localKeys[elemIdx])
144 Info<<
"StaticHashTable<T, Key, Hash>::found(const Key&) : "
145 <<
"Entry " << key <<
" not found in hash table\n";
153 template<
class T,
class Key,
class Hash>
162 const label hashIdx = hashKeyIndex(key);
163 const List<Key>& localKeys = keys_[hashIdx];
165 forAll(localKeys, elemIdx)
167 if (key == localKeys[elemIdx])
169 return iterator(*
this, hashIdx, elemIdx);
177 Info<<
"StaticHashTable<T, Key, Hash>::find(const Key&) : "
178 <<
"Entry " << key <<
" not found in hash table\n";
186 template<
class T,
class Key,
class Hash>
195 const label hashIdx = hashKeyIndex(key);
196 const List<Key>& localKeys = keys_[hashIdx];
198 forAll(localKeys, elemIdx)
200 if (key == localKeys[elemIdx])
210 Info<<
"StaticHashTable<T, Key, Hash>::find(const Key&) const : "
211 <<
"Entry " << key <<
" not found in hash table\n";
220 template<
class T,
class Key,
class Hash>
228 keys[keyI++] = iter.key();
235 template<
class T,
class Key,
class Hash>
243 const label hashIdx = hashKeyIndex(key);
247 forAll(localKeys, elemIdx)
249 if (key == localKeys[elemIdx])
256 if (existing == localKeys.
size())
259 List<T>& localObjects = objects_[hashIdx];
262 localObjects.setSize(existing+1);
264 localKeys[existing] = key;
265 localObjects[existing] = newEntry;
276 Info<<
"StaticHashTable<T, Key, Hash>::set"
277 "(const Key& key, T newEntry, true) : "
278 "Cannot insert " << key <<
" already in hash table\n";
287 objects_[hashIdx][existing] = newEntry;
294 template<
class T,
class Key,
class Hash>
299 List<Key>& localKeys = keys_[cit.hashIndex_];
300 List<T>& localObjects = objects_[cit.hashIndex_];
303 for (
label i = cit.elemIndex_+1; i < localKeys.
size(); i++)
305 localKeys[i-1] = localKeys[i];
306 localObjects[i-1] = localObjects[i];
308 localKeys.setSize(localKeys.
size()-1);
309 localObjects.setSize(localObjects.
size()-1);
312 iterator& it =
const_cast<iterator&
>(cit);
315 if (it.elemIndex_ < 0)
319 it.hashIndex_ = -it.hashIndex_ - 1;
328 Info<<
"StaticHashTable<T, Key, Hash>::erase(iterator&) : "
329 <<
"hashedEntry removed.\n";
340 Info<<
"StaticHashTable<T, Key, Hash>::erase(iterator&) : "
341 <<
"cannot remove hashedEntry from hash table\n";
350 template<
class T,
class Key,
class Hash>
366 template<
class T,
class Key,
class Hash>
376 for (iterator iter = this->begin(); iter != this->end(); ++iter)
388 template<
class T,
class Key,
class Hash>
393 if (newSize == keys_.size())
398 Info<<
"StaticHashTable<T, Key, Hash>::resize(const label) : "
399 <<
"new table size == old table size\n";
409 <<
"Illegal size " << newSize <<
" for StaticHashTable."
418 newTable.
insert(iter.key(), *iter);
424 endIter_.hashIndex_ = keys_.size();
425 endConstIter_.hashIndex_ = keys_.size();
429 template<
class T,
class Key,
class Hash>
434 keys_[hashIdx].clear();
435 objects_[hashIdx].clear();
442 template<
class T,
class Key,
class Hash>
450 template<
class T,
class Key,
class Hash>
460 keys_.transfer(ht.
keys_);
467 endIter_.hashIndex_ = keys_.size();
468 endConstIter_.hashIndex_ = keys_.size();
477 template<
class T,
class Key,
class Hash>
487 <<
"attempted assignment to self"
495 keys_.setSize(rhs.
keys_.size());
496 objects_.setSize(keys_.size());
499 endIter_.hashIndex_ = keys_.size();
500 endConstIter_.hashIndex_ = keys_.size();
511 insert(iter.key(), *iter);
515 template<
class T,
class Key,
class Hash>
527 if (fnd == cend() || fnd() != iter())
537 template<
class T,
class Key,
class Hash>