35 template<
class T,
class Key,
class Hash>
47 for (label i=0; i < capacity_; ++i)
59 template<
class T,
class Key,
class Hash>
64 unsigned avgChain = 0;
66 for (label i=0; i < capacity_; ++i)
69 for (node_type* ep = table_[i]; ep; ep = ep->next_)
86 os <<
"HashTable<T,Key,Hash>" 87 <<
" elements:" << size() <<
" slots:" <<
used <<
"/" << capacity_
88 <<
" chaining(avg/max):" << (
used ? (float(avgChain)/
used) : 0)
89 <<
"/" << maxChain <<
endl;
95 template<
class T,
class Key,
class Hash>
106 label i = this->size();
110 (i <= 1 || !shortLen)
115 os << i << token::BEGIN_LIST;
118 for (const_iterator iter = this->
cbegin(); iter != this->
cend(); ++iter)
120 if (i++)
os << token::SPACE;
124 os << token::END_LIST;
129 os <<
nl << i <<
nl << token::BEGIN_LIST <<
nl;
131 for (const_iterator iter = this->
cbegin(); iter != this->
cend(); ++iter)
133 os << iter.key() <<
nl;
136 os << token::END_LIST <<
nl;
144 template<
class T,
class Key,
class Hash>
150 HashTable<T, Key, Hash>& tbl = *
this;
161 "operator>>(Istream&, HashTable&) : " 162 "reading first token" 167 const label len = tok.labelToken();
170 const char delimiter = is.readBeginList(
"HashTable");
174 if (delimiter != token::BEGIN_LIST)
177 <<
"incorrect first token, '(', found " 182 if (2*len > tbl.capacity())
187 for (label i=0; i<len; ++i)
197 "operator>>(Istream&, HashTable&) : " 204 is.readEndList(
"HashTable");
206 else if (tok.isPunctuation(token::BEGIN_LIST))
209 while (!tok.isPunctuation(token::END_LIST))
221 "operator>>(Istream&, HashTable&) : " 231 <<
"incorrect first token, expected <int> or '(', found " 241 template<
class T,
class Key,
class Hash>
247 const HashTable<T, Key, Hash>& tbl = *
this;
249 const label len = tbl.
size();
254 os <<
nl << len <<
nl << token::BEGIN_LIST <<
nl;
257 for (
auto iter = tbl.cbegin(); iter != tbl.cend(); ++iter)
259 iter.print(
os) <<
nl;
262 os << token::END_LIST;
267 os << len << token::BEGIN_LIST << token::END_LIST;
277 template<
class T,
class Key,
class Hash>
281 HashTable<T, Key, Hash>& tbl
284 return tbl.readTable(is);
288 template<
class T,
class Key,
class Hash>
292 const HashTable<T, Key, Hash>& tbl
295 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.
std::conditional< std::is_same< Foam::zero, typename std::remove_cv< const regIOobject * >::type >::value, Detail::HashTableSingle< word >, Detail::HashTablePair< word, const regIOobject * > >::type node_type
A table entry (node) that encapsulates the key/val tuple with an additional linked-list entry for has...
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()
Clear 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)
HashTable()
Default construct with default (128) table capacity.
constexpr auto cbegin(const C &c) -> decltype(c.begin())
Return const_iterator to the beginning of the container c.
Bits that are independent of HashTable template parameters.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
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 ...