84 #ifndef Foam_HashTable_H 85 #define Foam_HashTable_H 103 template<
class T>
class List;
104 template<
class T>
class UList;
106 template<
class T,
unsigned N>
class FixedList;
107 template<
class T,
class Key,
class Hash>
class HashTable;
109 template<
class T,
class Key,
class Hash>
112 template<
class T,
class Key,
class Hash>
113 Ostream& operator<<(Ostream&, const HashTable<T, Key, Hash>&);
119 template<
class T,
class Key=word,
class Hash=Foam::Hash<Key>>
133 typedef typename std::conditional
181 class const_iterator;
202 inline label hashKeyIndex(
const Key&
key)
const;
206 template<
class... Args>
207 bool setEntry(
const bool overwrite,
const Key&
key, Args&&...
args);
219 template<
bool Const>
class Iterator;
222 friend class Iterator<true>;
225 friend class Iterator<false>;
249 HashTable(std::initializer_list<std::pair<Key, T>> list);
270 inline
T&
at(const Key&
key);
273 inline const
T&
at(const Key&
key) const;
276 inline
bool found(const Key&
key) const;
280 inline iterator
find(const Key&
key);
284 inline const_iterator
find(const Key&
key) const;
288 inline const_iterator
cfind(const Key&
key) const;
291 inline const
T&
lookup(const Key&
key, const
T& deflt) const;
304 template<class Compare>
312 template<class UnaryPredicate>
315 const UnaryPredicate& pred,
324 template<class UnaryPredicate>
327 const UnaryPredicate& pred,
336 template<class BinaryPredicate>
339 const BinaryPredicate& pred,
367 template<class UnaryPredicate>
370 const UnaryPredicate& pred,
377 template<class UnaryPredicate>
380 const UnaryPredicate& pred,
387 template<class BinaryPredicate>
390 const BinaryPredicate& pred,
399 template<class... Args>
404 template<class... Args>
409 inline
bool insert(const Key&
key, const
T& obj);
417 inline
bool set(const Key&
key, const
T& obj);
421 inline
bool set(const Key&
key,
T&& obj);
435 bool erase(const iterator& iter);
447 template<class AnyType, class AnyHash>
455 template<class InputIter>
456 inline label
erase(InputIter first, InputIter last);
473 template<class AnyType, class AnyHash>
493 template<class UnaryPredicate>
496 const UnaryPredicate& pred,
497 const
bool pruning = false
508 template<class UnaryPredicate>
511 const UnaryPredicate& pred,
512 const
bool pruning = false
523 template<class BinaryPredicate>
526 const BinaryPredicate& pred,
527 const
bool pruning = false
532 void resize(const label sz);
601 using iterator_category = std::forward_iterator_tag;
605 using table_type =
typename std::conditional
613 using node_type =
typename std::conditional
643 table_type* container_;
657 inline constexpr Iterator()
noexcept;
660 inline explicit Iterator(table_type* tbl);
663 Iterator(table_type* tbl,
const Key&
key);
669 inline void increment();
673 explicit operator const Iterator<Any>&()
const 675 return *
reinterpret_cast<const Iterator<Any>*
>(
this);
685 bool good()
const noexcept {
return entry_; }
691 const Key&
key()
const {
return entry_->key(); }
701 explicit operator bool()
const noexcept {
return entry_; }
708 return (entry_ == iter.entry_);
714 return (entry_ != iter.entry_);
728 public Iterator<false>
802 public Iterator<true>
873 return this->
operator=
885 class key_iterator_base
993 #include "HashTableI.H" 998 #ifndef NoHashTableC // Excluded from token.H
reference operator*() const
Return the key.
label countValues(const UnaryPredicate &pred, const bool invert=false) const
Count the number of values that satisfy the unary predicate.
node_type * entry_
The selected entry.
List< Key > tocKeys(const UnaryPredicate &pred, const bool invert=false) const
The table of contents (the keys) selected according to the unary predicate applied to the keys...
reference val() const
Const access to referenced object (value)
Factory class for creating a begin/end pair for any const iterator.
const_reference operator()() const
bool emplace(const Key &key, Args &&... args)
Emplace insert a new entry, not overwriting existing entries.
const node_type * node() const noexcept
Const access to the entry (node)
bool operator!=(const this_type &rhs) const
The opposite of the equality operation.
Internally used base for iterator and const_iterator.
Forward iterator with const access.
label filterValues(const UnaryPredicate &pred, const bool pruning=false)
Generalized means to filter table entries based on their values.
A 1D vector of objects of type <T> with a fixed length <N>.
const_iterator & operator++()
std::forward_iterator_tag iterator_category
label retain(const HashTable< AnyType, Key, AnyHash > &other)
Retain table entries given by keys of the other hash-table.
bool found(const Key &key) const
True if hashed key is found in table.
this_type::value_type value_type
this_type::key_type key_type
The key type.
Internal storage type for HashSet entries.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Ostream & print(Ostream &os, UIntType value, char off='0', char on='1')
Print 0/1 bits in the (unsigned) integral type.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
this_type::reference reference
iterator()=default
Default construct (end iterator)
friend Ostream & operator(Ostream &, const HashTable< T, Key, Hash > &tbl)
label size_type
The type that can represent the size of a HashTable.
Hash hasher
The third template parameter, the hash index method.
UPtrList< const node_type > csorted() const
Const access to the hash-table contents in sorted order (sorted by keys).
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.
const_reference val() const
Const access to referenced object (value)
label size() const noexcept
The number of elements in table.
bool iterator_erase(node_type *&entry, label &index)
Low-level entry erasure using iterator internals.
Lookup type of boundary radiation properties.
iterator end() noexcept
iterator to signal the end (for any HashTable)
typename std::conditional< Const, const this_type::node_type, this_type::node_type >::type node_type
The node-type being addressed.
const_reference operator*() const
Const access to referenced object (value)
const_iterator & operator=(const const_iterator &)=default
Copy assignment.
void resize(const label sz)
Resize the hash table for efficiency.
bool operator==(const this_type &rhs) const
Equality. Tables are equal if all keys and values are equal, independent of order or underlying stora...
List< Key > tocEntries(const BinaryPredicate &pred, const bool invert=false) const
The table of contents (the keys) selected according to the binary predicate applied to the keys and v...
bool emplace_set(const Key &key, Args &&... args)
Emplace set an entry, overwriting any existing entries.
T * pointer
Pointer type for storing into value_type objects.
Forward iterator with non-const access.
const node_type * node() const noexcept
Const access to the entry (node)
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
label countEntries(const BinaryPredicate &pred, const bool invert=false) const
Count the number of entries that satisfy the binary predicate.
void swap(HashTable< T, Key, Hash > &rhs)
Swap contents into this table.
reference operator*() const
Const access to referenced object (value)
reference operator()() const
this_type::key_type value_type
const_iterator cfind(const Key &key) const
Find and return an const_iterator set at the hashed entry.
Ostream & writeKeys(Ostream &os, const label shortLen=0) const
Write unordered keys (list), with line-breaks when length exceeds shortLen.
label capacity() const noexcept
The size of the underlying table.
A class for handling words, derived from Foam::string.
iterator find(const Key &key)
Find and return an iterator set at the hashed entry.
label filterEntries(const BinaryPredicate &pred, const bool pruning=false)
Generalized means to filter table entries based on their key/value.
Ostream & printInfo(Ostream &os) const
Print information.
Istream & operator>>(Istream &, directionInfo &)
void clear()
Clear all entries from table.
this_type::node_type node_type
constexpr key_iterator_base() noexcept
Default construct (end iterator)
this_type::const_pointer const_pointer
T mapped_type
The first template parameter, type of objects contained.
this_type::pointer pointer
label difference_type
The type to represent the difference between two iterators.
iterator begin()
iterator set to the beginning of the HashTable
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.
label countKeys(const UnaryPredicate &pred, const bool invert=false) const
Count the number of keys that satisfy the unary predicate.
A HashTable similar to std::unordered_map.
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
key_iterator_base & operator++()
const T & const_reference
Const reference to the stored value_type.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
bool empty() const noexcept
True if the hash table is empty.
An iterator wrapper for returning a reference to the key.
this_type::const_reference const_reference
T value_type
Same as mapped_type for OpenFOAM HashTables.
Key key_type
The second template parameter, type of keys used.
OBJstream os(runTime.globalPath()/outputName)
HashTable()
Default construct with default (128) table capacity.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
std::conditional< std::is_same< zero::null, typename std::remove_cv< T >::type >::value, Detail::HashTableSingle< Key >, Detail::HashTablePair< Key, T > >::type node_type
A table entry (node) that encapsulates the key/val tuple with an additional linked-list entry for has...
const Vector< label > N(dict.get< Vector< label >>("N"))
bool erase(const iterator &iter)
Erase an entry specified by given iterator.
std::forward_iterator_tag iterator_category
labelList invert(const label len, const labelUList &map)
Create an inverse one-to-one mapping.
Bits that are independent of HashTable template parameters.
constexpr Iterator() noexcept
Default construct. Also the same as the end iterator.
Hash function class. The default definition is for primitives. Non-primitives used to hash entries on...
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
void transfer(HashTable< T, Key, Hash > &rhs)
Transfer contents into this table.
UPtrList< const node_type > sorted() const
Const access to the hash-table contents in sorted order (sorted by keys).
T & reference
Reference to the stored value_type.
this_type::difference_type difference_type
Internal storage type for HashTable entries.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
label filterKeys(const UnaryPredicate &pred, const bool pruning=false)
Generalized means to filter table entries based on their keys.
Includes some standard C++ headers, defines global macros and templates used in multiple places by Op...
this_type::difference_type difference_type
friend class Iterator< false >
An iterator with non-const access to HashTable internals.
const T * const_pointer
Const pointer type for the stored value_type.
List< Key > toc() const
The table of contents (the keys) in unsorted order.
const_iterator cbegin() const
const_iterator set to the beginning of the HashTable
this_type::mapped_type mapped_type
Foam::argList args(argc, argv)
const_iterator_pair< const_key_iterator, this_type > keys() const
A const iterator begin/end pair for iterating over keys.
constexpr const_iterator cend() const noexcept
const_iterator to signal the end (for any HashTable)
bool set(const Key &key, const T &obj)
Copy assign a new entry, overwriting existing entries.
A keyword and a list of tokens is an 'entry'.
void clearStorage()
Clear the table entries and the table itself.
reference operator()() const
List< Key > tocValues(const UnaryPredicate &pred, const bool invert=false) const
The table of contents (the keys) selected according to the unary predicate applied to the values...