84#ifndef Foam_HashTable_H
85#define Foam_HashTable_H
93#include <initializer_list>
104template<
class T>
class List;
105template<
class T>
class UList;
106template<
class T>
class UPtrList;
107template<
class T,
unsigned N>
class FixedList;
108template<
class T,
class Key,
class Hash>
class HashTable;
110template<
class T,
class Key,
class Hash>
113template<
class T,
class Key,
class Hash>
120template<
class T,
class Key=word,
class Hash=Foam::Hash<Key>>
134 typedef typename std::conditional
136 std::is_same<zero::null, typename std::remove_cv<T>::type>::value,
203 inline label hashKeyIndex(
const Key& key)
const;
207 template<
class... Args>
208 bool setEntry(
const bool overwrite,
const Key& key, Args&&...
args);
220 template<
bool Const>
class Iterator;
250 HashTable(std::initializer_list<std::pair<Key, T>> list);
271 inline
T&
at(const Key& key);
274 inline const
T&
at(const Key& key) const;
277 inline
bool found(const Key& key) const;
292 inline const
T&
lookup(const Key& key, const
T& deflt) const;
305 template<class Compare>
313 template<class UnaryPredicate>
316 const UnaryPredicate& pred,
325 template<class UnaryPredicate>
328 const UnaryPredicate& pred,
337 template<class BinaryPredicate>
340 const BinaryPredicate& pred,
368 template<class UnaryPredicate>
371 const UnaryPredicate& pred,
378 template<class UnaryPredicate>
381 const UnaryPredicate& pred,
388 template<class BinaryPredicate>
391 const BinaryPredicate& pred,
400 template<class... Args>
401 inline
bool emplace(const Key& key, Args&&...
args);
405 template<class... Args>
410 inline
bool insert(const Key& key, const
T& obj);
414 inline
bool insert(const Key& key,
T&& obj);
418 inline
bool set(const Key& key, const
T& obj);
422 inline
bool set(const Key& key,
T&& obj);
440 bool erase(const Key& key);
448 template<class AnyType, class AnyHash>
453 inline label
erase(std::initializer_list<Key>
keys);
456 template<class InputIter>
457 inline label
erase(InputIter first, InputIter last);
474 template<class AnyType, class AnyHash>
494 template<class UnaryPredicate>
497 const UnaryPredicate& pred,
498 const
bool pruning = false
509 template<class UnaryPredicate>
512 const UnaryPredicate& pred,
513 const
bool pruning = false
524 template<class BinaryPredicate>
527 const BinaryPredicate& pred,
528 const
bool pruning = false
533 void resize(const label sz);
555 inline const
T&
operator[](const Key& key) const;
563 inline
T&
operator()(const Key& key, const
T& deflt);
570 void operator=(std::initializer_list<std::pair<Key,
T>> rhs);
614 using node_type =
typename std::conditional
643 inline const Key& key() const;
699 inline
void increment();
865 return this->
operator=
934 inline iterator
begin();
937 inline const_iterator
begin()
const;
940 inline const_iterator
cbegin()
const;
985#include "HashTableI.H"
A 1D vector of objects of type <T> with a fixed length <N>.
Factory class for creating a begin/end pair for any const iterator.
Internally used base for iterator and const_iterator.
typename std::conditional< Const, const this_type::mapped_type, this_type::mapped_type >::type mapped_type
The object type being addressed.
this_type::key_type key_type
The key type.
std::forward_iterator_tag iterator_category
typename std::conditional< Const, const this_type::node_type, this_type::node_type >::type node_type
The node-type being addressed.
this_type::difference_type difference_type
typename std::conditional< Const, const this_type, this_type >::type table_type
The HashTable container type.
Forward iterator with const access.
const node_type * node() const noexcept
Const access to the entry (node)
this_type::key_type key_type
reference val() const
Const access to referenced object (value)
reference operator()() const
const this_type::mapped_type mapped_type
const_iterator & operator++()
const_iterator()=default
Default construct (end iterator)
std::forward_iterator_tag iterator_category
this_type::const_pointer pointer
const_iterator(const const_iterator &)=default
Copy construct.
this_type::node_type node_type
const_iterator & operator=(const const_iterator &)=default
Copy assignment.
this_type::difference_type difference_type
reference operator*() const
Const access to referenced object (value)
this_type::const_reference reference
const_iterator(const iterator &iter)
Implicit conversion from dissimilar access type.
const this_type::value_type value_type
const_iterator(const Iterator< Any > &iter)
Copy construct from any access type.
const_iterator & operator=(const iterator &iter)
Forward iterator with non-const access.
const node_type * node() const noexcept
Const access to the entry (node)
this_type::mapped_type mapped_type
const_reference operator()() const
this_type::key_type key_type
iterator()=default
Default construct (end iterator)
this_type::value_type value_type
reference operator*()
Non-const access to referenced object (value)
const_reference val() const
Const access to referenced object (value)
node_type * node() noexcept
Non-const access to the entry (node)
std::forward_iterator_tag iterator_category
this_type::const_reference const_reference
this_type::reference reference
this_type::node_type node_type
this_type::difference_type difference_type
this_type::const_pointer const_pointer
reference val()
Non-const access to referenced object (value)
const_reference operator*() const
Const access to referenced object (value)
this_type::pointer pointer
iterator(const Iterator< false > &iter)
Copy construct from similar access type.
An iterator wrapper for returning a reference to the key.
key_iterator_base(const Iter &iter)
Copy construct with implicit conversion.
reference operator()() const
reference operator*() const
Return the key.
key_iterator_base operator++(int)
constexpr key_iterator_base() noexcept
Default construct (end iterator)
key_iterator_base & operator++()
this_type::key_type value_type
A HashTable similar to std::unordered_map.
List< Key > tocEntries(const BinaryPredicate &pred, const bool invert=false) const
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
label countEntries(const BinaryPredicate &pred, const bool invert=false) const
Count the number of entries that satisfy the binary predicate.
label size_type
The type that can represent the size of a HashTable.
HashTable(this_type &&rhs)
Move construct.
const_iterator_pair< const_key_iterator, this_type > keys() const
A const iterator begin/end pair for iterating over keys.
Ostream & writeKeys(Ostream &os, const label shortLen=0) const
label countKeys(const UnaryPredicate &pred, const bool invert=false) const
Count the number of keys that satisfy the unary predicate.
List< Key > toc() const
The table of contents (the keys) in unsorted order.
label difference_type
The type to represent the difference between two iterators.
HashTable< T, Key, Hash > this_type
The template instance used for this HashTable.
T value_type
Same as mapped_type for OpenFOAM HashTables.
bool set(const Key &key, const T &obj)
Copy assign a new entry, overwriting existing entries.
Key key_type
The second template parameter, type of keys used.
label retain(const HashTable< AnyType, Key, AnyHash > &other)
Retain table entries given by keys of the other hash-table.
Ostream & printInfo(Ostream &os) const
Print information.
bool empty() const noexcept
True if the hash table is empty.
iterator begin()
iterator set to the beginning of the HashTable
const_iterator cbegin() const
const_iterator set to the beginning of the HashTable
const T * const_pointer
Const pointer type for the stored value_type.
const_iterator cfind(const Key &key) const
Find and return an const_iterator set at the hashed entry.
bool iterator_erase(node_type *&entry, label &index)
Low-level entry erasure using iterator internals.
T * pointer
Pointer type for storing into value_type objects.
void resize(const label sz)
Resize the hash table for efficiency.
void clearStorage()
Clear the table entries and the table itself.
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
bool emplace_set(const Key &key, Args &&... args)
Emplace set an entry, overwriting any existing entries.
T mapped_type
The first template parameter, type of objects contained.
label filterValues(const UnaryPredicate &pred, const bool pruning=false)
Generalized means to filter table entries based on their values.
label capacity() const noexcept
The size of the underlying table.
List< Key > tocValues(const UnaryPredicate &pred, const bool invert=false) const
std::conditional< std::is_same< zero::null, typenamestd::remove_cv< T >::type >::value, Detail::HashTableSingle< Key >, Detail::HashTablePair< Key, T > >::type node_type
void transfer(HashTable< T, Key, Hash > &rhs)
Transfer contents into this table.
label size() const noexcept
The number of elements in table.
T & reference
Reference to the stored value_type.
void swap(HashTable< T, Key, Hash > &rhs)
Swap contents into this table.
label filterEntries(const BinaryPredicate &pred, const bool pruning=false)
Generalized means to filter table entries based on their key/value.
friend Ostream & operator(Ostream &, const HashTable< T, Key, Hash > &tbl)
label filterKeys(const UnaryPredicate &pred, const bool pruning=false)
Generalized means to filter table entries based on their keys.
HashTable(const this_type &ht)
Copy construct.
iterator find(const Key &key)
Find and return an iterator set at the hashed entry.
label countValues(const UnaryPredicate &pred, const bool invert=false) const
Count the number of values that satisfy the unary predicate.
UPtrList< const node_type > sorted() const
HashTable()
Default construct with default (128) table capacity.
UPtrList< const node_type > csorted() const
bool erase(const iterator &iter)
Erase an entry specified by given iterator.
bool emplace(const Key &key, Args &&... args)
Emplace insert a new entry, not overwriting existing entries.
void clear()
Clear all entries from table.
iterator end() noexcept
iterator to signal the end (for any HashTable)
List< Key > tocKeys(const UnaryPredicate &pred, const bool invert=false) const
constexpr const_iterator cend() const noexcept
const_iterator to signal the end (for any HashTable)
T & at(const Key &key)
Find and return a hashed entry. FatalError if it does not exist.
Hash hasher
The third template parameter, the hash index method.
const T & const_reference
Const reference to the stored value_type.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
A keyword and a list of tokens is an 'entry'.
Lookup type of boundary radiation properties.
OBJstream os(runTime.globalPath()/outputName)
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Istream & operator>>(Istream &, directionInfo &)
labelList invert(const label len, const labelUList &map)
Create an inverse one-to-one mapping.
Foam::argList args(argc, argv)
Internal storage type for HashTable entries.
Internal storage type for HashSet entries.
Bits that are independent of HashTable template parameters.
Hash function class. The default definition is for primitives. Non-primitives used to hash entries on...
const Vector< label > N(dict.get< Vector< label > >("N"))