35 template<
class T,
class Key,
class Hash>
46 template<
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;
82 template<
class T,
class Key,
class Hash>
93 label i = this->size();
102 os << i << token::BEGIN_LIST;
105 for (const_iterator iter = this->
cbegin(); iter != this->
cend(); ++iter)
107 if (i++)
os << token::SPACE;
111 os << token::END_LIST;
116 os <<
nl << i <<
nl << token::BEGIN_LIST <<
nl;
118 for (const_iterator iter = this->
cbegin(); iter != this->
cend(); ++iter)
120 os << iter.key() <<
nl;
123 os << token::END_LIST <<
nl;
131 template<
class T,
class Key,
class Hash>
137 HashTable<T, Key, Hash>& tbl = *
this;
148 "operator>>(Istream&, HashTable&) : " 149 "reading first token" 154 const label len = tok.labelToken();
157 const char delimiter = is.readBeginList(
"HashTable");
161 if (delimiter != token::BEGIN_LIST)
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");
190 else if (tok.isPunctuation(token::BEGIN_LIST))
193 while (!tok.isPunctuation(token::END_LIST))
205 "operator>>(Istream&, HashTable&) : " 215 <<
"incorrect first token, expected <int> or '(', found " 225 template<
class T,
class Key,
class Hash>
231 const HashTable<T, Key, Hash>& tbl = *
this;
233 const label len = tbl.
size();
238 os <<
nl << len <<
nl << token::BEGIN_LIST <<
nl;
241 for (
auto iter = tbl.cbegin(); iter != tbl.cend(); ++iter)
243 iter.print(
os) <<
nl;
246 os << token::END_LIST;
251 os << len << token::BEGIN_LIST << token::END_LIST;
261 template<
class T,
class Key,
class Hash>
265 HashTable<T, Key, Hash>& tbl
268 return tbl.readTable(is);
272 template<
class T,
class Key,
class Hash>
276 const HashTable<T, Key, Hash>& tbl
279 return tbl.writeTable(
os);
errorManipArg< error, int > exit(error &err, const int errNo=1)
labelHashSet used(const bitSet &select)
Convert a bitset to a labelHashSet of the indices used.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
constexpr char nl
The newline '\n' character (0x0a)
Ostream & endl(Ostream &os)
Add newline and flush stream.
HashTable() noexcept
Default construct: empty without allocation (capacity=0)
label size() const noexcept
The number of elements in table.
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
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.
Istream & operator>>(Istream &, directionInfo &)
void clear()
Remove all entries from table.
constexpr auto cend(const C &c) -> decltype(c.end())
Return const_iterator to the end of the container c.
A HashTable similar to std::unordered_map.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
OBJstream os(runTime.globalPath()/outputName)
constexpr auto cbegin(const C &c) -> decltype(c.begin())
Return const_iterator to the beginning of the container c.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Hash function class. The default definition is for primitives. Non-primitives used to hash entries on...
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...