Go to the documentation of this file.
92 #include <initializer_list>
106 template<
class T,
class Key,
class Hash>
class HashTable;
112 template<
class T,
class Key=word,
class Hash=
string::hash>
120 typedef typename std::conditional
144 inline label hashKeyIndex(
const Key& key)
const;
148 template<
class... Args>
149 bool setEntry(
const bool overwrite,
const Key& key, Args&&...
args);
198 class const_iterator;
203 template<
bool Const>
class Iterator;
206 friend class Iterator<true>;
209 friend class Iterator<false>;
232 HashTable(std::initializer_list<std::pair<Key, T>> list);
244 inline label
capacity() const noexcept;
247 inline label
size() const noexcept;
250 inline
bool empty() const noexcept;
253 inline
T&
at(const Key& key);
256 inline const
T&
at(const Key& key) const;
259 inline
bool found(const Key& key) const;
263 inline iterator
find(const Key& key);
267 inline const_iterator
find(const Key& key) const;
271 inline const_iterator
cfind(const Key& key) const;
274 inline const
T&
lookup(const Key& key, const
T& deflt) const;
287 template<class Compare>
295 template<class UnaryPredicate>
298 const UnaryPredicate& pred,
307 template<class UnaryPredicate>
310 const UnaryPredicate& pred,
319 template<class BinaryPredicate>
322 const BinaryPredicate& pred,
332 template<class UnaryPredicate>
335 const UnaryPredicate& pred,
342 template<class UnaryPredicate>
345 const UnaryPredicate& pred,
352 template<class BinaryPredicate>
355 const BinaryPredicate& pred,
364 template<class... Args>
365 inline
bool emplace(const Key& key, Args&&...
args);
369 template<class... Args>
374 inline
bool insert(const Key& key, const
T& obj);
378 inline
bool insert(const Key& key,
T&& obj);
382 inline
bool set(const Key& key, const
T& obj);
386 inline
bool set(const Key& key,
T&& obj);
400 bool erase(const iterator& iter);
404 bool erase(const Key& key);
412 template<class AnyType, class AnyHash>
417 inline label
erase(std::initializer_list<Key>
keys);
420 template<class InputIter>
421 inline label
erase(InputIter first, InputIter last);
438 template<class AnyType, class AnyHash>
458 template<class UnaryPredicate>
461 const UnaryPredicate& pred,
462 const
bool pruning = false
473 template<class UnaryPredicate>
476 const UnaryPredicate& pred,
477 const
bool pruning = false
488 template<class BinaryPredicate>
491 const BinaryPredicate& pred,
492 const
bool pruning = false
497 void resize(const label sz);
516 inline
T& operator[](const Key& key);
519 inline const
T& operator[](const Key& key) const;
524 inline
T& operator()(const Key& key);
527 inline
T& operator()(const Key& key, const
T& deflt);
534 void operator=(std::initializer_list<std::pair<Key,
T>> rhs);
541 bool operator==(const
this_type& rhs) const;
544 bool operator!=(const
this_type& rhs) const;
578 using node_type =
typename std::conditional
581 const this_type::node_type,
601 inline bool good() const noexcept;
604 inline
bool found() const noexcept;
607 inline const Key& key() const;
617 explicit inline operator
bool() const noexcept;
622 inline
bool operator==(const
Iterator<Any>& iter) const noexcept;
625 inline
bool operator!=(const
Iterator<Any>& iter) const noexcept;
651 inline constexpr
Iterator() noexcept;
663 inline
void increment();
667 explicit operator const
Iterator<Any>&()
const
729 inline const_reference
operator()()
const {
return this->
val(); }
809 return this->
operator=
869 const_iterator_pair<const_key_iterator, this_type>
keys()
const
871 return const_iterator_pair<const_key_iterator, this_type>(*
this);
878 inline iterator
begin();
881 inline const_iterator
begin()
const;
884 inline const_iterator
cbegin()
const;
887 inline iterator
end() noexcept;
890 inline const_iterator
end() const noexcept;
893 inline constexpr const_iterator
cend() const noexcept;
910 template<class
T, class Key, class
Hash>
913 template<class
T, class Key, class
Hash>
923 #include "HashTableI.H"
const_reference val() const
Const access to referenced object (value)
A keyword and a list of tokens is an 'entry'.
label size() const noexcept
The number of elements in table.
reference val() const
Const access to referenced object (value)
T & reference
Reference to the stored value_type.
this_type::reference reference
std::forward_iterator_tag iterator_category
iterator(const Iterator< false > &iter)
Copy construct from similar access type.
Forward iterator with non-const access.
bool emplace_set(const Key &key, Args &&... args)
Emplace set an entry, overwriting any existing entries.
List< Key > toc() const
The table of contents (the keys) in unsorted order.
reference operator()() const
iterator end() noexcept
iterator to signal the end (for any HashTable)
reference val()
Non-const access to referenced object (value)
key_iterator_base< iterator > key_iterator
Forward iterator returning the key.
const_iterator cbegin() const
const_iterator set to the beginning of the HashTable
this_type::mapped_type mapped_type
label countEntries(const BinaryPredicate &pred, const bool invert=false) const
Count the number of entries that satisfy the binary predicate.
Forward iterator with const access.
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
bool emplace(const Key &key, Args &&... args)
Emplace insert a new entry, not overwriting existing entries.
constexpr const_iterator cend() const noexcept
const_iterator to signal the end (for any HashTable)
reference operator*() const
Const access to referenced object (value)
Internal storage type for HashSet entries.
An iterator wrapper for returning a reference to the key.
label countValues(const UnaryPredicate &pred, const bool invert=false) const
Count the number of values that satisfy the unary predicate.
key_iterator_base(const Iter &iter)
Copy construct with implicit conversion.
label filterValues(const UnaryPredicate &pred, const bool pruning=false)
Generalized means to filter table entries based on their values.
List< Key > tocKeys(const UnaryPredicate &pred, const bool invert=false) const
reference operator*()
Non-const access to referenced object (value)
label retain(const HashTable< AnyType, Key, AnyHash > &other)
Retain table entries given by keys of the other hash-table.
label countKeys(const UnaryPredicate &pred, const bool invert=false) const
Count the number of keys that satisfy the unary predicate.
this_type::value_type value_type
this_type::key_type key_type
The key type.
const_iterator()=default
Default construct (end iterator)
this_type::key_type key_type
typename std::conditional< Const, const this_type::mapped_type, this_type::mapped_type >::type mapped_type
The object type being addressed.
this_type::const_pointer pointer
labelList invert(const label len, const labelUList &map)
Create an inverse one-to-one mapping.
label filterEntries(const BinaryPredicate &pred, const bool pruning=false)
Generalized means to filter table entries based on their key/value.
const_iterator & operator++()
iterator()=default
Default construct (end iterator)
T value_type
Same as mapped_type for OpenFOAM HashTables.
this_type::key_type value_type
std::forward_iterator_tag iterator_category
this_type::const_pointer const_pointer
T mapped_type
The first template parameter, type of objects contained.
this_type::pointer pointer
const_iterator(const iterator &iter)
Implicit conversion from dissimilar access type.
Hash hasher
The third template parameter, the hash index method.
Hash function class. The default definition is for primitives, non-primitives used to hash entries on...
reference operator()() const
const_iterator(const Iterator< Any > &iter)
Copy construct from any access type.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
bool erase(const iterator &iter)
Erase an entry specified by given iterator.
key_iterator_base< const_iterator > const_key_iterator
Forward const iterator returning the key.
typename std::conditional< Const, const this_type::node_type, this_type::node_type >::type node_type
The node-type being addressed.
const typedef T * const_pointer
Const pointer type for the stored value_type.
const this_type::value_type value_type
Key key_type
The second template parameter, type of keys used.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
void resize(const label sz)
Resize the hash table for efficiency.
HashTable()
Default construct with default (128) table capacity.
List< Key > tocEntries(const BinaryPredicate &pred, const bool invert=false) const
Bits that are independent of HashTable template parameters.
Lookup type of boundary radiation properties.
label filterKeys(const UnaryPredicate &pred, const bool pruning=false)
Generalized means to filter table entries based on their keys.
bool iterator_erase(node_type *&entry, label &index)
Low-level entry erasure using iterator internals.
const this_type::mapped_type mapped_type
const_reference operator*() const
Const access to referenced object (value)
constexpr key_iterator_base() noexcept
Default construct (end iterator)
T * pointer
Pointer type for storing into value_type objects.
Ostream & writeKeys(Ostream &os, const label shortLen=0) const
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
iterator find(const Key &key)
Find and return an iterator set at the hashed entry.
void transfer(HashTable< T, Key, Hash > &rhs)
Transfer contents into this table.
void swap(HashTable< T, Key, Hash > &rhs)
Swap contents into this table.
this_type::difference_type difference_type
A HashTable similar to std::unordered_map.
const_iterator_pair< const_key_iterator, this_type > keys() const
A const iterator begin/end pair for iterating over keys.
Internal storage type for HashTable entries.
label difference_type
The type to represent the difference between two iterators.
this_type::difference_type difference_type
iterator begin()
iterator set to the beginning of the HashTable
label capacity() const noexcept
The size of the underlying table.
const_iterator cfind(const Key &key) const
Find and return an const_iterator set at the hashed entry.
this_type::key_type key_type
void clearStorage()
Clear the table entries and the table itself.
Ostream & printInfo(Ostream &os) const
Print information.
const_iterator & operator=(const const_iterator &)=default
Copy assignment.
void clear()
Clear all entries from table.
this_type::const_reference reference
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
typename std::conditional< Const, const this_type, this_type >::type table_type
The HashTable container type.
const_iterator & operator=(const iterator &iter)
this_type::const_reference const_reference
key_iterator_base & operator++()
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
A 1D vector of objects of type <T> with a fixed length <N>.
Ostream & print(Ostream &os, UIntType value, char off='0', char on='1')
Print 0/1 bits in the (unsigned) integral type.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
const_reference operator()() const
Internally used base for iterator and const_iterator.
bool set(const Key &key, const T &obj)
Copy assign a new entry, overwriting existing entries.
List< Key > tocValues(const UnaryPredicate &pred, const bool invert=false) const
this_type::difference_type difference_type
bool empty() const noexcept
True if the hash table is empty.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
const Vector< label > N(dict.get< Vector< label >>("N"))
bool found(const Key &key) const
Return true if hashed entry is found in table.
Foam::argList args(argc, argv)
reference operator*() const
Return the key.
const typedef T & const_reference
Const reference to the stored value_type.
key_iterator_base operator++(int)
std::forward_iterator_tag iterator_category
label size_type
The type that can represent the size of a HashTable.
HashTable< T, Key, Hash > this_type
The template instance used for this HashTable.
T & at(const Key &key)
Find and return a hashed entry. FatalError if it does not exist.