Go to the documentation of this file.
38 template<
class T,
class Key,
class Hash>
45 template<
class T,
class Key,
class Hash>
55 table_ =
new node_type*[capacity_];
56 for (label i=0; i < capacity_; ++i)
64 template<
class T,
class Key,
class Hash>
69 for (const_iterator iter = ht.
cbegin(); iter != ht.
cend(); ++iter)
71 insert(iter.key(), iter.val());
76 template<
class T,
class Key,
class Hash>
81 capacity_(rhs.capacity_),
90 template<
class T,
class Key,
class Hash>
93 std::initializer_list<std::pair<Key, T>> list
98 for (
const auto& keyval : list)
100 set(keyval.first, keyval.second);
107 template<
class T,
class Key,
class Hash>
120 template<
class T,
class Key,
class Hash>
126 for (const_iterator iter =
cbegin(); iter !=
cend(); ++iter)
128 list[
count++] = iter.key();
135 template<
class T,
class Key,
class Hash>
145 template<
class T,
class Key,
class Hash>
146 template<
class Compare>
159 template<
class T,
class Key,
class Hash>
160 template<
class UnaryPredicate>
163 const UnaryPredicate& pred,
170 for (const_iterator iter =
cbegin(); iter !=
cend(); ++iter)
174 list[
count++] = iter.key();
185 template<
class T,
class Key,
class Hash>
186 template<
class UnaryPredicate>
189 const UnaryPredicate& pred,
196 for (const_iterator iter =
cbegin(); iter !=
cend(); ++iter)
200 list[
count++] = iter.key();
211 template<
class T,
class Key,
class Hash>
212 template<
class BinaryPredicate>
215 const BinaryPredicate& pred,
222 for (const_iterator iter =
cbegin(); iter !=
cend(); ++iter)
226 list[
count++] = iter.key();
237 template<
class T,
class Key,
class Hash>
238 template<
class UnaryPredicate>
241 const UnaryPredicate& pred,
247 for (const_iterator iter =
cbegin(); iter !=
cend(); ++iter)
259 template<
class T,
class Key,
class Hash>
260 template<
class UnaryPredicate>
263 const UnaryPredicate& pred,
269 for (const_iterator iter =
cbegin(); iter !=
cend(); ++iter)
281 template<
class T,
class Key,
class Hash>
282 template<
class BinaryPredicate>
285 const BinaryPredicate& pred,
291 for (const_iterator iter =
cbegin(); iter !=
cend(); ++iter)
303 template<
class T,
class Key,
class Hash>
304 template<
class... Args>
307 const bool overwrite,
317 const label index = hashKeyIndex(key);
319 node_type* curr =
nullptr;
320 node_type* prev =
nullptr;
322 for (node_type* ep = table_[index]; ep; ep = ep->next_)
324 if (key == ep->key())
336 new node_type(table_[index], key, std::forward<Args>(
args)...);
339 if (
double(size_)/capacity_ > 0.8 && capacity_ < maxTableSize)
354 if (!node_type::stores_value())
359 node_type* ep = curr->next_;
366 ep =
new node_type(ep, key, std::forward<Args>(
args)...);
391 template<
class T,
class Key,
class Hash>
399 iterator& it =
const_cast<iterator&
>(iter);
401 return iterator_erase(it.entry_, it.index_);
405 template<
class T,
class Key,
class Hash>
408 auto iter =
find(key);
413 template<
class T,
class Key,
class Hash>
414 template<
class InputIter>
425 const label nTotal = this->size();
426 changed < nTotal && first != last;
430 if (this->
erase(*first))
440 template<
class T,
class Key,
class Hash>
443 std::initializer_list<Key> keys
446 return erase(keys.begin(), keys.end());
450 template<
class T,
class Key,
class Hash>
461 template<
class T,
class Key,
class Hash>
471 template<
class T,
class Key,
class Hash>
472 template<
class AnyType,
class AnyHash>
478 const label nTotal = this->size();
481 if (other.
size() <= nTotal)
487 auto iter = other.
cbegin();
488 changed < nTotal && iter != other.
cend();
492 if (
erase(iter.key()))
503 iterator iter =
begin();
504 changed < nTotal && iter !=
end();
519 template<
class T,
class Key,
class Hash>
520 template<
class AnyType,
class AnyHash>
526 const label nTotal = this->size();
539 for (iterator iter =
begin(); iter !=
end(); ++iter)
552 template<
class T,
class Key,
class Hash>
555 const label newCapacity = HashTableCore::canonicalSize(sz);
556 const label oldCapacity = capacity_;
558 if (newCapacity == oldCapacity)
566 else if (!newCapacity)
572 <<
"HashTable contains " << size_ <<
" cannot resize(0)" <<
nl;
590 auto oldTable = table_;
591 capacity_ = newCapacity;
593 table_ =
new node_type*[capacity_];
594 for (label i=0; i < capacity_; ++i)
602 for (label i=0; nMove && i < oldCapacity; ++i)
604 for (node_type* ep = oldTable[i]; ep; )
606 node_type* next = ep->next_;
610 const label newIdx = hashKeyIndex(ep->key());
612 ep->next_ = table_[newIdx];
619 oldTable[i] =
nullptr;
629 template<
class T,
class Key,
class Hash>
632 for (label i=0; size_ && i<capacity_; ++i)
634 for (node_type* ep = table_[i]; ep; )
636 node_type* next = ep->next_;
648 template<
class T,
class Key,
class Hash>
656 template<
class T,
class Key,
class Hash>
670 template<
class T,
class Key,
class Hash>
683 template<
class T,
class Key,
class Hash>
684 template<
class UnaryPredicate>
687 const UnaryPredicate& pred,
693 for (iterator iter =
begin(); iter !=
end(); ++iter)
698 (pred(iter.key()) ? pruning : !pruning)
710 template<
class T,
class Key,
class Hash>
711 template<
class UnaryPredicate>
714 const UnaryPredicate& pred,
720 for (iterator iter =
begin(); iter !=
end(); ++iter)
725 (pred(iter.val()) ? pruning : !pruning)
737 template<
class T,
class Key,
class Hash>
738 template<
class BinaryPredicate>
741 const BinaryPredicate& pred,
747 for (iterator iter =
begin(); iter !=
end(); ++iter)
752 (pred(iter.key(), iter.val()) ? pruning : !pruning)
766 template<
class T,
class Key,
class Hash>
787 for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
789 insert(iter.key(), iter.val());
794 template<
class T,
class Key,
class Hash>
797 std::initializer_list<std::pair<Key, T>> rhs
810 for (
const auto& keyval : rhs)
812 set(keyval.first, keyval.second);
817 template<
class T,
class Key,
class Hash>
832 template<
class T,
class Key,
class Hash>
839 if (size() != rhs.size())
844 for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
846 const const_iterator other(this->cfind(iter.key()));
848 if (!other.good() || other.val() != iter.val())
858 template<
class T,
class Key,
class Hash>
868 template<
class T,
class Key,
class Hash>
875 if (rhs.size() ||
this != &rhs)
879 for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
881 insert(iter.key(), iter.val());
srcOptions insert("case", fileName(rootDirSource/caseDirSource))
label size() const noexcept
The number of elements in table.
const_iterator cbegin() const
Return const_iterator to begin traversing the constant UList.
constexpr auto begin(C &c) -> decltype(c.begin())
Return iterator to the beginning of the container c.
const_iterator cend() const
Return const_iterator to end traversing the constant UList.
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
label countEntries(const BinaryPredicate &pred, const bool invert=false) const
Count the number of entries that satisfy the binary predicate.
constexpr const_iterator cend() const noexcept
const_iterator to signal the end (for any HashTable)
label countValues(const UnaryPredicate &pred, const bool invert=false) const
Count the number of values that satisfy the unary predicate.
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
label retain(const HashTable< AnyType, Key, AnyHash > &other)
Retain table entries given by keys of the other hash-table.
void Swap(DynamicList< T, SizeMin1 > &a, DynamicList< T, SizeMin2 > &b)
label countKeys(const UnaryPredicate &pred, const bool invert=false) const
Count the number of keys that satisfy the unary predicate.
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.
Hash function class. The default definition is for primitives, non-primitives used to hash entries on...
patchWriters resize(patchIds.size())
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
bool erase(const iterator &iter)
Erase an entry specified by given iterator.
#define DebugInFunction
Report an information message using Foam::Info.
void resize(const label sz)
Resize the hash table for efficiency.
HashTable()
Default construct with default (128) table capacity.
const_iterator cend() const
Return const_iterator to end traversing the constant FixedList.
List< Key > tocEntries(const BinaryPredicate &pred, const bool invert=false) const
Bits that are independent of HashTable template parameters.
void resize(const label newSize)
Adjust allocated size of list.
label filterKeys(const UnaryPredicate &pred, const bool pruning=false)
Generalized means to filter table entries based on their keys.
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
label find(const ListType &input, const UnaryPredicate &pred, const label start=0)
Find index of the first occurrence that satisfies the predicate.
constexpr auto cend(const C &c) -> decltype(c.end())
Return const_iterator to the end of the container c.
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.
const_iterator cbegin() const
Return const_iterator to begin traversing the constant FixedList.
void swap(HashTable< T, Key, Hash > &rhs)
Swap contents into this table.
A HashTable similar to std::unordered_map.
void clearStorage()
Clear the table entries and the table itself.
constexpr auto cbegin(const C &c) -> decltype(c.begin())
Return const_iterator to the beginning of the container c.
void clear()
Clear all entries from table.
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
A 1D vector of objects of type <T> with a fixed length <N>.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
List< Key > tocValues(const UnaryPredicate &pred, const bool invert=false) const
bool empty() const noexcept
True if the hash table is empty.
bool found(const Key &key) const
Return true if hashed entry is found in table.
Foam::argList args(argc, argv)
#define WarningInFunction
Report a warning using Foam::Warning.