Go to the documentation of this file.
34 template<
class T,
class Key,
class Hash>
39 tableSize_(HashTableCore::canonicalSize(size)),
44 table_ =
new hashedEntry*[tableSize_];
46 for (
label hashIdx = 0; hashIdx < tableSize_; hashIdx++)
54 template<
class T,
class Key,
class Hash>
59 tableSize_(ht.tableSize_),
64 table_ =
new hashedEntry*[tableSize_];
66 for (
label hashIdx = 0; hashIdx < tableSize_; hashIdx++)
71 for (const_iterator iter = ht.cbegin(); iter != ht.cend(); ++iter)
78 template<
class T,
class Key,
class Hash>
81 const Xfer<HashTable<T, Key, Hash> >& ht
95 template<
class T,
class Key,
class Hash>
108 template<
class T,
class Key,
class Hash>
113 const label hashIdx = hashKeyIndex(key);
115 for (hashedEntry* ep = table_[hashIdx]; ep; ep = ep->next_)
127 Info<<
"HashTable<T, Key, Hash>::found(const Key& key) : "
128 <<
"Entry " << key <<
" not found in hash table\n";
136 template<
class T,
class Key,
class Hash>
145 const label hashIdx = hashKeyIndex(key);
147 for (hashedEntry* ep = table_[hashIdx]; ep; ep = ep->next_)
151 return iterator(
this, ep, hashIdx);
159 Info<<
"HashTable<T, Key, Hash>::find(const Key& key) : "
160 <<
"Entry " << key <<
" not found in hash table\n";
168 template<
class T,
class Key,
class Hash>
177 const label hashIdx = hashKeyIndex(key);
179 for (hashedEntry* ep = table_[hashIdx]; ep; ep = ep->next_)
183 return const_iterator(
this, ep, hashIdx);
191 Info<<
"HashTable<T, Key, Hash>::find(const Key& key) const : "
192 <<
"Entry " << key <<
" not found in hash table\n";
196 return const_iterator();
200 template<
class T,
class Key,
class Hash>
206 for (const_iterator iter = cbegin(); iter != cend(); ++iter)
208 keys[keyI++] = iter.
key();
215 template<
class T,
class Key,
class Hash>
225 template<
class T,
class Key,
class Hash>
238 const label hashIdx = hashKeyIndex(key);
240 hashedEntry* existing = 0;
241 hashedEntry* prev = 0;
243 for (hashedEntry* ep = table_[hashIdx]; ep; ep = ep->next_)
256 table_[hashIdx] =
new hashedEntry(key, table_[hashIdx], newEntry);
259 if (
double(nElmts_)/tableSize_ > 0.8 && tableSize_ < maxTableSize)
264 Info<<
"HashTable<T, Key, Hash>::set"
265 "(const Key& key, T newEntry) : "
266 "Doubling table size\n";
280 Info<<
"HashTable<T, Key, Hash>::set"
281 "(const Key& key, T newEntry, true) : "
282 "Cannot insert " << key <<
" already in hash table\n";
291 hashedEntry* ep =
new hashedEntry(key, existing->next_, newEntry);
300 table_[hashIdx] = ep;
310 template<
class T,
class Key,
class Hash>
378 template<
class T,
class Key,
class Hash>
386 template<
class T,
class Key,
class Hash>
393 template<
class T,
class Key,
class Hash>
400 for (
label keyI = 0; count < nTotal && keyI < keys.size(); ++keyI)
402 if (
erase(keys[keyI]))
412 template<
class T,
class Key,
class Hash>
413 template<
class AnyType,
class AnyHash>
435 template<
class T,
class Key,
class Hash>
445 Info<<
"HashTable<T, Key, Hash>::resize(const label) : "
446 <<
"new table size == old table size\n";
464 hashedEntry** oldTable =
table_;
466 tmpTable->
table_ = oldTable;
472 template<
class T,
class Key,
class Hash>
481 hashedEntry* ep =
table_[hashIdx];
482 while (hashedEntry* next = ep->next_)
496 template<
class T,
class Key,
class Hash>
504 template<
class T,
class Key,
class Hash>
512 resize(newSize ? newSize : 2);
517 template<
class T,
class Key,
class Hash>
540 template<
class T,
class Key,
class Hash>
550 <<
"attempted assignment to self"
571 template<
class T,
class Key,
class Hash>
587 if (fnd == cend() || fnd() != iter())
597 template<
class T,
class Key,
class Hash>
friend class iterator
Declare friendship with the iterator.
void resize(const label newSize)
Resize the hash table for efficiency.
An STL-conforming iterator.
List< Key > toc() const
Return the table of contents.
void shrink()
Shrink the allocated table to approx. twice number of elements.
void transfer(HashTable< T, Key, Hash > &)
Transfer the contents of the argument table into this table.
const_iterator cbegin() const
const_iterator set to the beginning of the HashTable
triSurfaceToAgglom resize(surfacesMesh.size())
An STL-conforming const_iterator.
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
HashTable(const label size=128)
Construct given initial table size.
hashedEntry * entryPtr_
Current element.
friend class const_iterator
Declare friendship with the const_iterator.
bool set(const Key &, const T &newElmt, bool protect)
Assign a new hashedEntry to a possibly already existing key.
hashedEntry * next_
Pointer to next hashedEntry in sub-list.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Structure to hold a hashed entry with SLList for collisions.
bool operator==(const HashTable< T, Key, Hash > &) const
Equality. Hash tables are equal if the keys and values are equal.
hashedEntry ** table_
The table of primary entries.
bool erase(const iterator &)
Erase a hashedEntry specified by given iterator.
HashTable< T, Key, Hash > * hashTable_
Pointer to the HashTable for which this is an iterator.
label size() const
Return number of elements in table.
bool erase()
Erase the HashTable element at the current position.
label tableSize_
Number of primary entries allocated in table.
bool found(const Key &) const
Return true if hashedEntry is found in table.
errorManip< error > abort(error &err)
List< Key > sortedToc() const
Return the table of contents as a sorted list.
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
An STL-conforming hash table.
const Key & key() const
Return the Key corresponding to the iterator.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
iterator begin()
Iterator set to the beginning of the HashTable.
void clearStorage()
Clear the table entries and the table itself.
void clear()
Clear all entries from table.
label nElmts_
The current number of elements in table.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
static label canonicalSize(const label)
Return a canonical (power-of-two) size.
timeIndices insert(timeIndex, timeDirs[timeI].value())
label hashIndex_
Current hash index.