Go to the documentation of this file.
35 template<
class T,
class Key,
class Hash>
45 table_ =
new node_type*[capacity_];
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>
161 "operator>>(Istream&, HashTable&) : "
162 "reading first token"
167 const label len = tok.labelToken();
174 if (delimiter != token::BEGIN_LIST)
177 <<
"incorrect first token, '(', found "
187 for (label i=0; i<len; ++i)
197 "operator>>(Istream&, 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);
label size() const noexcept
The number of elements in table.
char readBeginList(const char *funcName)
Begin read of list data, starts with '(' or '{'.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
bool fatalCheck(const char *operation) const
Check IOstream status for given operation.
char readEndList(const char *funcName)
End read of list data, ends with ')' or '}'.
Istream & operator>>(Istream &, directionInfo &)
Ostream & endl(Ostream &os)
Add newline and flush stream.
A token holds an item read from Istream.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
void resize(const label sz)
Resize the hash table for efficiency.
HashTable()
Default construct with default (128) table capacity.
Bits that are independent of HashTable template parameters.
OBJstream os(runTime.globalPath()/outputName)
constexpr auto cend(const C &c) -> decltype(c.end())
Return const_iterator to the end of the container c.
Ostream & writeKeys(Ostream &os, const label shortLen=0) const
errorManipArg< error, int > exit(error &err, const int errNo=1)
A HashTable similar to std::unordered_map.
label capacity() const noexcept
The size of the underlying table.
Ostream & printInfo(Ostream &os) const
Print information.
constexpr auto cbegin(const C &c) -> decltype(c.begin())
Return const_iterator to the beginning of the container c.
void clear()
Clear all entries from table.
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
labelHashSet used(const bitSet &select)
Convert a bitset to a labelHashSet of the indices used.
void putBack(const token &tok)
Put back a token. Only a single put back is permitted.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...