Go to the documentation of this file.
92 #include <initializer_list>
106 template<
class T,
class Key,
class Hash>
class HashTable;
108 template<
class T,
class Key,
class Hash>
111 template<
class T,
class Key,
class Hash>
118 template<
class T,
class Key=word,
class Hash=Foam::Hash<Key>>
126 typedef typename std::conditional
150 inline label hashKeyIndex(
const Key&
key)
const;
154 template<
class... Args>
155 bool setEntry(
const bool overwrite,
const Key&
key, Args&&...
args);
210 class const_iterator;
215 template<
bool Const>
class Iterator;
218 friend class Iterator<true>;
221 friend class Iterator<false>;
244 HashTable(std::initializer_list<std::pair<Key, T>> list);
256 inline label
capacity() const noexcept;
259 inline label
size() const noexcept;
262 inline
bool empty() const noexcept;
265 inline
T&
at(const Key&
key);
268 inline const
T&
at(const Key&
key) const;
271 inline
bool found(const Key&
key) const;
275 inline iterator
find(const Key&
key);
279 inline const_iterator
find(const Key&
key) const;
283 inline const_iterator
cfind(const Key&
key) const;
286 inline const
T&
lookup(const Key&
key, const
T& deflt) const;
299 template<class Compare>
307 template<class UnaryPredicate>
310 const UnaryPredicate& pred,
319 template<class UnaryPredicate>
322 const UnaryPredicate& pred,
331 template<class BinaryPredicate>
334 const BinaryPredicate& pred,
344 template<class UnaryPredicate>
347 const UnaryPredicate& pred,
354 template<class UnaryPredicate>
357 const UnaryPredicate& pred,
364 template<class BinaryPredicate>
367 const BinaryPredicate& pred,
376 template<class... Args>
381 template<class... Args>
386 inline
bool insert(const Key&
key, const
T& obj);
394 inline
bool set(const Key&
key, const
T& obj);
398 inline
bool set(const Key&
key,
T&& obj);
412 bool erase(const iterator& iter);
424 template<class AnyType, class AnyHash>
429 inline label
erase(std::initializer_list<Key>
keys);
432 template<class InputIter>
433 inline label
erase(InputIter first, InputIter last);
450 template<class AnyType, class AnyHash>
470 template<class UnaryPredicate>
473 const UnaryPredicate& pred,
474 const
bool pruning = false
485 template<class UnaryPredicate>
488 const UnaryPredicate& pred,
489 const
bool pruning = false
500 template<class BinaryPredicate>
503 const BinaryPredicate& pred,
504 const
bool pruning = false
509 void resize(const label sz);
546 void operator=(std::initializer_list<std::pair<Key,
T>> rhs);
590 using node_type =
typename std::conditional
593 const this_type::node_type,
613 inline bool good() const noexcept;
616 inline
bool found() const noexcept;
619 inline const Key&
key() const;
629 explicit inline
operator bool() const noexcept;
663 inline constexpr
Iterator() noexcept;
675 inline
void increment();
741 inline const_reference
operator()()
const {
return this->
val(); }
821 return this->
operator=
881 const_iterator_pair<const_key_iterator, this_type>
keys()
const
883 return const_iterator_pair<const_key_iterator, this_type>(*
this);
890 inline iterator
begin();
893 inline const_iterator
begin()
const;
896 inline const_iterator
cbegin()
const;
899 inline iterator
end() noexcept;
902 inline const_iterator
end() const noexcept;
905 inline constexpr const_iterator
cend() const noexcept;
941 #include "HashTableI.H"
946 #ifndef NoHashTableC // Excluded from token.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.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
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.
Istream & operator>>(Istream &, directionInfo &)
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
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
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)
OBJstream os(runTime.globalPath()/outputName)
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)
friend Ostream & operator(Ostream &, const HashTable< T, Key, Hash > &tbl)
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.