26 #ifndef ListHashTable_C 27 #define ListHashTable_C 43 unsigned int goodSize = size;
45 if (goodSize & (goodSize - 1))
49 while (goodSize <
unsigned(size))
61 template<
class T,
class Key,
class Hash>
66 objects_(keys_.size()),
68 endIter_(*this, keys_.size(), 0),
69 endConstIter_(*this, keys_.size(), 0)
74 <<
"Illegal size " << size <<
" for ListHashTable." 80 template<
class T,
class Key,
class Hash>
88 objects_(ht.objects_),
90 endIter_(*
this, keys_.size(), 0),
91 endConstIter_(*
this, keys_.size(), 0)
95 template<
class T,
class Key,
class Hash>
105 endIter_(*
this, 0, 0),
106 endConstIter_(*
this, 0, 0)
114 template<
class T,
class Key,
class Hash>
121 template<
class T,
class Key,
class Hash>
126 const label hashIdx = hashKeyIndex(key);
127 const List<Key>& localKeys = keys_[hashIdx];
129 forAll(localKeys, elemIdx)
131 if (key == localKeys[elemIdx])
141 InfoInFunction <<
"Entry " << key <<
" not found in hash table\n";
149 template<
class T,
class Key,
class Hash>
158 const label hashIdx = hashKeyIndex(key);
159 const List<Key>& localKeys = keys_[hashIdx];
161 forAll(localKeys, elemIdx)
163 if (key == localKeys[elemIdx])
165 return iterator(*
this, hashIdx, elemIdx);
173 InfoInFunction <<
"Entry " << key <<
" not found in hash table\n";
181 template<
class T,
class Key,
class Hash>
190 const label hashIdx = hashKeyIndex(key);
191 const List<Key>& localKeys = keys_[hashIdx];
193 forAll(localKeys, elemIdx)
195 if (key == localKeys[elemIdx])
205 InfoInFunction <<
"Entry " << key <<
" not found in hash table\n";
213 template<
class T,
class Key,
class Hash>
221 keys[keyI++] = iter.key();
228 template<
class T,
class Key,
class Hash>
236 const label hashIdx = hashKeyIndex(key);
240 forAll(localKeys, elemIdx)
242 if (key == localKeys[elemIdx])
249 if (existing == localKeys.
size())
252 List<T>& localObjects = objects_[hashIdx];
255 localObjects.
setSize(existing+1);
257 localKeys[existing] = key;
258 localObjects[existing] = newEntry;
270 <<
"Cannot insert " << key <<
" already in hash table\n";
279 objects_[hashIdx][existing] = newEntry;
286 template<
class T,
class Key,
class Hash>
291 List<Key>& localKeys = keys_[cit.hashIndex_];
292 List<T>& localObjects = objects_[cit.hashIndex_];
295 for (
label i = cit.elemIndex_+1; i < localKeys.
size(); i++)
297 localKeys[i-1] = localKeys[i];
298 localObjects[i-1] = localObjects[i];
307 if (it.elemIndex_ < 0)
311 it.hashIndex_ = -it.hashIndex_ - 1;
332 <<
"Cannot remove hashedEntry from hash table\n";
341 template<
class T,
class Key,
class Hash>
357 template<
class T,
class Key,
class Hash>
379 template<
class T,
class Key,
class Hash>
384 if (newSize == keys_.size())
399 <<
"Illegal size " << newSize <<
" for ListHashTable." 408 newTable.
insert(iter.key(), *iter);
414 endIter_.hashIndex_ = keys_.size();
415 endConstIter_.hashIndex_ = keys_.size();
419 template<
class T,
class Key,
class Hash>
424 keys_[hashIdx].clear();
425 objects_[hashIdx].clear();
432 template<
class T,
class Key,
class Hash>
440 template<
class T,
class Key,
class Hash>
450 keys_.transfer(ht.keys_);
451 objects_.transfer(ht.objects_);
453 nElmts_ = ht.nElmts_;
457 endIter_.hashIndex_ = keys_.size();
458 endConstIter_.hashIndex_ = keys_.size();
460 ht.endIter_.hashIndex_ = 0;
461 ht.endConstIter_.hashIndex_ = 0;
467 template<
class T,
class Key,
class Hash>
468 void Foam::ListHashTable<T, Key, Hash>::operator=
477 <<
"attempted assignment to self" 485 keys_.setSize(rhs.keys_.size());
486 objects_.setSize(keys_.size());
489 endIter_.hashIndex_ = keys_.size();
490 endConstIter_.hashIndex_ = keys_.size();
501 insert(iter.key(), *iter);
506 template<
class T,
class Key,
class Hash>
507 void Foam::ListHashTable<T, Key, Hash>::operator=
516 <<
"attempted assignment to self" 524 template<
class T,
class Key,
class Hash>
525 bool Foam::ListHashTable<T, Key, Hash>::operator==
536 if (fnd ==
cend() || fnd() != iter())
546 template<
class T,
class Key,
class Hash>
547 bool Foam::ListHashTable<T, Key, Hash>::operator!=
Iterator< const T &, const ListHashTable< T, Key, Hash > &> const_iterator
#define forAll(list, i)
Loop across all elements in list.
Template-invariant bits for ListHashTable.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
const iterator & end()
Iterator set to beyond the end of the ListHashTable.
bool operator==(const ListHashTable< T, Key, Hash > &) const
Equality. Two hash tables are equal if all contents of first are.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void size(const label)
Override size to be inconsistent with allocated storage.
label count(const ListType &l, typename ListType::const_reference x)
Count the number of occurrences of a value in a list.
ListHashTableCore()
Construct null.
void transfer(ListHashTable< T, Key, Hash > &)
Transfer the contents of the argument table into this table.
static label canonicalSize(const label)
Return a canonical (power-of-two) size.
iterator begin()
Iterator set to the beginning of the ListHashTable.
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
bool erase(const iterator &it)
Erase an hashed entry specified by given iterator.
~ListHashTable()
Destructor.
errorManip< error > abort(error &err)
ListHashTable(const label size=128)
Construct given initial table size.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
STL conforming hash table using contiguous lists rather than linked lists.
bool insert(const Key &key, const T &newElmt)
Insert a new hashed entry.
void setSize(const label)
Reset size of List.
Iterator< T &, ListHashTable< T, Key, Hash > &> iterator
iterator find(const Key &key)
Find and return an iterator set at the hashed entry.
const const_iterator & cend() const
const_iterator set to beyond the end of the ListHashTable
void clearStorage()
Clear the table entries and the table itself.
List< Key > toc() const
Return the table of contents.
const_iterator cbegin() const
const_iterator set to the beginning of the ListHashTable
void resize(const label newSize)
Resize the hash table for efficiency.
void clear()
Clear all entries from table.
bool found(const Key &key) const
Return true if hashed entry is found in table.
#define InfoInFunction
Report an information message using Foam::Info.