35template<
class T,
class Key,
class Hash>
46template<
class T,
class Key,
class Hash>
51 unsigned avgChain = 0;
53 for (label i=0; i < capacity_; ++i)
56 for (node_type* ep = table_[i]; ep; ep = ep->next_)
73 os <<
"HashTable<T,Key,Hash>"
74 <<
" elements:" << size() <<
" slots:" <<
used <<
"/" << capacity_
75 <<
" chaining(avg/max):" << (
used ? (float(avgChain)/
used) : 0)
76 <<
"/" << maxChain <<
endl;
82template<
class T,
class Key,
class Hash>
93 label i = this->size();
105 for (
const_iterator iter = this->cbegin(); iter != this->cend(); ++iter)
118 for (const_iterator iter = this->cbegin(); iter != this->cend(); ++iter)
120 os << iter.key() <<
nl;
131template<
class T,
class Key,
class Hash>
132Foam::Istream& Foam::HashTable<T, Key, Hash>::readTable
148 "operator>>(Istream&, HashTable&) : "
149 "reading first token"
154 const label len = tok.labelToken();
157 const char delimiter = is.readBeginList(
"HashTable");
164 <<
"incorrect first token, '(', found "
169 tbl.reserve(tbl.size() + len);
171 for (label i=0; i<len; ++i)
181 "operator>>(Istream&, HashTable&) : "
188 is.readEndList(
"HashTable");
205 "operator>>(Istream&, HashTable&) : "
215 <<
"incorrect first token, expected <int> or '(', found "
225template<
class T,
class Key,
class Hash>
226Foam::Ostream& Foam::HashTable<T, Key, Hash>::writeTable
233 const label len = tbl.
size();
241 for (
auto iter = tbl.cbegin(); iter != tbl.cend(); ++iter)
243 iter.print(
os) <<
nl;
261template<
class T,
class Key,
class Hash>
262Foam::Istream& Foam::operator>>
268 return tbl.readTable(is);
272template<
class T,
class Key,
class Hash>
273Foam::Ostream& Foam::operator<<
279 return tbl.writeTable(
os);
Forward iterator with const access.
A HashTable similar to std::unordered_map.
Ostream & writeKeys(Ostream &os, const label shortLen=0) const
Write unordered keys (list), with line-breaks when length exceeds shortLen.
Ostream & printInfo(Ostream &os) const
Print information.
const_iterator cbegin() const
const_iterator set to the beginning of the HashTable
void reserve(label numEntries)
Reserve space for at least the specified number of elements (not the number of buckets) and regenerat...
label size() const noexcept
The number of elements in table.
std::conditional_t< std::is_same_v< Foam::zero, std::remove_cv_t< T > >, Detail::HashTableSingle< Key >, Detail::HashTablePair< Key, T > > node_type
A table entry (node) that encapsulates the key/val tuple with an additional linked-list entry for has...
void clear()
Remove all entries from table.
constexpr const_iterator cend() const noexcept
const_iterator to signal the end (for any HashTable)
friend Istream & operator>>(Istream &, HashTable< T, Key, Hash > &tbl)
constexpr HashTable() noexcept
Default construct: empty without allocation (capacity=0).
bool fatalCheck(const char *operation) const
Check IOstream status for given operation.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
char readEndList(const char *funcName)
End read of list data, ends with ')' or '}'.
char readBeginList(const char *funcName)
Begin read of list data, starts with '(' or '{'.
void putBack(const token &tok)
Put back a token (copy). Only a single put back is permitted.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
A token holds an item read from Istream.
@ BEGIN_LIST
Begin list [isseparator].
@ END_LIST
End list [isseparator].
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
OBJstream os(runTime.globalPath()/outputName)
labelHashSet used(const bitSet &select)
Convert a bitset to a labelHashSet of the indices used.
constexpr auto key(const Type &t) noexcept
Helper function to return the enum value.
Ostream & endl(Ostream &os)
Add newline and flush stream.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
errorManipArg< error, int > exit(error &err, const int errNo=1)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
constexpr char nl
The newline '\n' character (0x0a).
Hash function class. The default definition is for primitives. Non-primitives used to hash entries on...