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;
146 template<
class T,
class Key,
class Hash>
158 token firstToken(is);
162 "operator>>(Istream&, HashTable&) : "
163 "reading first token"
166 if (firstToken.isLabel())
168 const label len = firstToken.labelToken();
171 const char delimiter = is.readBeginList(
"HashTable");
175 if (delimiter != token::BEGIN_LIST)
178 <<
"incorrect first token, '(', found " << firstToken.info()
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 (firstToken.isPunctuation())
208 if (firstToken.pToken() != token::BEGIN_LIST)
211 <<
"incorrect first token, '(', found " << firstToken.info()
219 lastToken.isPunctuation()
220 && lastToken.pToken() == token::END_LIST
224 is.putBack(lastToken);
234 "operator>>(Istream&, HashTable&) : "
244 <<
"incorrect first token, expected <int> or '(', found "
254 template<
class T,
class Key,
class Hash>
258 const HashTable<T, Key, Hash>& tbl
261 const label len = tbl.size();
266 os <<
nl << len <<
nl << token::BEGIN_LIST <<
nl;
269 for (
auto iter = tbl.cbegin(); iter != tbl.cend(); ++iter)
271 iter.print(os) <<
nl;
274 os << token::END_LIST;
279 os << len << token::BEGIN_LIST << token::END_LIST;
bool fatalCheck(const char *operation) const
Check IOstream status for given operation.
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)....
HashTable()
Default construct with default (128) table capacity.
Bits that are independent of HashTable template parameters.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
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.
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.
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.
#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,...