HashTable.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2017-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #ifndef HashTable_C
30 #define HashTable_C
31 
32 #include "HashTable.H"
33 #include "List.H"
34 #include "FixedList.H"
35 
36 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
37 
38 template<class T, class Key, class Hash>
40 :
41  HashTable<T, Key, Hash>(128)
42 {}
43 
44 
45 template<class T, class Key, class Hash>
47 :
48  HashTableCore(),
49  size_(0),
50  capacity_(HashTableCore::canonicalSize(size)),
51  table_(nullptr)
52 {
53  if (capacity_)
54  {
55  table_ = new node_type*[capacity_];
56  for (label i=0; i < capacity_; ++i)
57  {
58  table_[i] = nullptr;
59  }
60  }
61 }
62 
63 
64 template<class T, class Key, class Hash>
66 :
67  HashTable<T, Key, Hash>(ht.capacity_)
68 {
69  for (const_iterator iter = ht.cbegin(); iter != ht.cend(); ++iter)
70  {
71  insert(iter.key(), iter.val());
72  }
73 }
74 
75 
76 template<class T, class Key, class Hash>
77 Foam::HashTable<T, Key, Hash>::HashTable(HashTable<T, Key, Hash>&& rhs)
78 :
79  HashTableCore(),
80  size_(rhs.size_),
81  capacity_(rhs.capacity_),
82  table_(rhs.table_)
83 {
84  rhs.size_ = 0;
85  rhs.capacity_ = 0;
86  rhs.table_ = nullptr;
87 }
88 
89 
90 template<class T, class Key, class Hash>
92 (
93  std::initializer_list<std::pair<Key, T>> list
94 )
95 :
96  HashTable<T, Key, Hash>(2*list.size())
97 {
98  for (const auto& keyval : list)
99  {
100  set(keyval.first, keyval.second);
101  }
102 }
103 
104 
105 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
106 
107 template<class T, class Key, class Hash>
109 {
110  if (table_)
111  {
112  clear();
113  delete[] table_;
114  }
115 }
116 
117 
118 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
119 
120 template<class T, class Key, class Hash>
122 {
123  List<Key> list(size_);
124  label count = 0;
125 
126  for (const_iterator iter = cbegin(); iter != cend(); ++iter)
127  {
128  list[count++] = iter.key();
129  }
130 
131  return list;
132 }
133 
134 
135 template<class T, class Key, class Hash>
137 {
138  List<Key> list(this->toc());
139  Foam::sort(list);
140 
141  return list;
142 }
143 
144 
145 template<class T, class Key, class Hash>
146 template<class Compare>
148 (
149  const Compare& comp
150 ) const
151 {
152  List<Key> list(this->toc());
153  Foam::sort(list, comp);
154 
155  return list;
156 }
157 
158 
159 template<class T, class Key, class Hash>
160 template<class UnaryPredicate>
162 (
163  const UnaryPredicate& pred,
164  const bool invert
165 ) const
166 {
167  List<Key> list(size_);
168  label count = 0;
169 
170  for (const_iterator iter = cbegin(); iter != cend(); ++iter)
171  {
172  if ((pred(iter.key()) ? !invert : invert))
173  {
174  list[count++] = iter.key();
175  }
176  }
177 
178  list.resize(count);
179  Foam::sort(list);
180 
181  return list;
182 }
183 
184 
185 template<class T, class Key, class Hash>
186 template<class UnaryPredicate>
188 (
189  const UnaryPredicate& pred,
190  const bool invert
191 ) const
192 {
193  List<Key> list(size_);
194  label count = 0;
195 
196  for (const_iterator iter = cbegin(); iter != cend(); ++iter)
197  {
198  if ((pred(iter.val()) ? !invert : invert))
199  {
200  list[count++] = iter.key();
201  }
202  }
203 
204  list.resize(count);
205  Foam::sort(list);
206 
207  return list;
208 }
209 
210 
211 template<class T, class Key, class Hash>
212 template<class BinaryPredicate>
214 (
215  const BinaryPredicate& pred,
216  const bool invert
217 ) const
218 {
219  List<Key> list(size_);
220  label count = 0;
221 
222  for (const_iterator iter = cbegin(); iter != cend(); ++iter)
223  {
224  if ((pred(iter.key(), iter.val()) ? !invert : invert))
225  {
226  list[count++] = iter.key();
227  }
228  }
229 
230  list.resize(count);
231  Foam::sort(list);
232 
233  return list;
234 }
235 
236 
237 template<class T, class Key, class Hash>
238 template<class UnaryPredicate>
240 (
241  const UnaryPredicate& pred,
242  const bool invert
243 ) const
244 {
245  label count = 0;
246 
247  for (const_iterator iter = cbegin(); iter != cend(); ++iter)
248  {
249  if ((pred(iter.key()) ? !invert : invert))
250  {
251  ++count;
252  }
253  }
254 
255  return count;
256 }
257 
258 
259 template<class T, class Key, class Hash>
260 template<class UnaryPredicate>
262 (
263  const UnaryPredicate& pred,
264  const bool invert
265 ) const
266 {
267  label count = 0;
268 
269  for (const_iterator iter = cbegin(); iter != cend(); ++iter)
270  {
271  if ((pred(iter.val()) ? !invert : invert))
272  {
273  ++count;
274  }
275  }
276 
277  return count;
278 }
279 
280 
281 template<class T, class Key, class Hash>
282 template<class BinaryPredicate>
284 (
285  const BinaryPredicate& pred,
286  const bool invert
287 ) const
288 {
289  label count = 0;
290 
291  for (const_iterator iter = cbegin(); iter != cend(); ++iter)
292  {
293  if ((pred(iter.key(), iter.val()) ? !invert : invert))
294  {
295  ++count;
296  }
297  }
298 
299  return count;
300 }
301 
302 
303 template<class T, class Key, class Hash>
304 template<class... Args>
306 (
307  const bool overwrite,
308  const Key& key,
309  Args&&... args
310 )
311 {
312  if (!capacity_)
313  {
314  resize(2);
315  }
316 
317  const label index = hashKeyIndex(key);
318 
319  node_type* curr = nullptr;
320  node_type* prev = nullptr;
321 
322  for (node_type* ep = table_[index]; ep; ep = ep->next_)
323  {
324  if (key == ep->key())
325  {
326  curr = ep;
327  break;
328  }
329  prev = ep;
330  }
331 
332  if (!curr)
333  {
334  // Not found, insert it at the head
335  table_[index] =
336  new node_type(table_[index], key, std::forward<Args>(args)...);
337 
338  ++size_;
339  if (double(size_)/capacity_ > 0.8 && capacity_ < maxTableSize)
340  {
341  #ifdef FULLDEBUG
342  DebugInFunction << "Doubling table size\n";
343  #endif
344 
345  resize(2*capacity_);
346  }
347  }
348  else if (overwrite)
349  {
350  // Overwrite current entry (Perl convention).
351 
352  // Can skip if the value is not stored anyhow (Eg, HashSet)
353  // - this avoids a useless delete/new
354  if (!node_type::stores_value())
355  {
356  return true;
357  }
358 
359  node_type* ep = curr->next_; // next in the linked list
360 
361  // In some cases the delete/new could be avoided in favour of move
362  // assignment, but cannot be certain that all objects support this
363  // or that it behaves the same as a copy construct.
364 
365  delete curr;
366  ep = new node_type(ep, key, std::forward<Args>(args)...);
367 
368  // Replace current element - within list or insert at the head
369  if (prev)
370  {
371  prev->next_ = ep;
372  }
373  else
374  {
375  table_[index] = ep;
376  }
377  }
378  else
379  {
380  // Do not overwrite existing entry (STL 'insert' convention)
381  #ifdef FULLDEBUG
382  DebugInFunction << "Not inserting " << key << ": already in table\n";
383  #endif
384  return false;
385  }
386 
387  return true;
388 }
389 
390 
391 template<class T, class Key, class Hash>
392 bool Foam::HashTable<T, Key, Hash>::erase(const iterator& iter)
393 {
394  // NOTE: we use (const iterator&) here, but treat its contents as mutable.
395  //
396  // The parameter should be (iterator&), but then the compiler doesn't find
397  // it correctly and tries to call as (iterator) instead.
398 
399  iterator& it = const_cast<iterator&>(iter);
400 
401  return iterator_erase(it.entry_, it.index_);
402 }
403 
404 
405 template<class T, class Key, class Hash>
407 {
408  iterator iter(find(key));
409  return erase(iter);
410 }
411 
412 
413 template<class T, class Key, class Hash>
414 template<class InputIter>
415 inline Foam::label Foam::HashTable<T, Key, Hash>::erase
416 (
417  InputIter first,
418  InputIter last
419 )
420 {
421  label changed = 0;
422 
423  for
424  (
425  const label nTotal = this->size();
426  changed < nTotal && first != last; // terminate early
427  ++first
428  )
429  {
430  if (this->erase(*first))
431  {
432  ++changed;
433  }
434  }
435 
436  return changed;
437 }
438 
439 
440 template<class T, class Key, class Hash>
441 inline Foam::label Foam::HashTable<T, Key, Hash>::erase
442 (
443  std::initializer_list<Key> keys
444 )
445 {
446  return erase(keys.begin(), keys.end());
447 }
448 
449 
450 template<class T, class Key, class Hash>
451 template<unsigned N>
452 inline Foam::label Foam::HashTable<T, Key, Hash>::erase
453 (
454  const FixedList<Key, N>& keys
455 )
456 {
457  return erase(keys.cbegin(), keys.cend());
458 }
459 
460 
461 template<class T, class Key, class Hash>
462 inline Foam::label Foam::HashTable<T, Key, Hash>::erase
463 (
464  const UList<Key>& keys
465 )
466 {
467  return erase(keys.cbegin(), keys.cend());
468 }
469 
470 
471 template<class T, class Key, class Hash>
472 template<class AnyType, class AnyHash>
474 (
476 )
477 {
478  const label nTotal = this->size();
479  label changed = 0;
480 
481  if (other.size() <= nTotal)
482  {
483  // The other is smaller/same-size, use its keys for removal
484 
485  for
486  (
487  auto iter = other.cbegin();
488  changed < nTotal && iter != other.cend(); // Terminate early
489  ++iter
490  )
491  {
492  if (erase(iter.key()))
493  {
494  ++changed;
495  }
496  }
497  }
498  else
499  {
500  // We are smaller: remove if found in the other hash
501  for
502  (
503  iterator iter = begin();
504  changed < nTotal && iter != end(); // Terminate early
505  ++iter
506  )
507  {
508  if (other.found(iter.key()) && erase(iter))
509  {
510  ++changed;
511  }
512  }
513  }
514 
515  return changed;
516 }
517 
518 
519 template<class T, class Key, class Hash>
520 template<class AnyType, class AnyHash>
522 (
524 )
525 {
526  const label nTotal = this->size();
527  label changed = 0;
528 
529  if (other.empty())
530  {
531  // Trivial case
532  changed = nTotal;
533  this->clear();
534  }
535  else
536  {
537  // Inverted logic: remove if *not* found in the other hash
538 
539  for (iterator iter = begin(); iter != end(); ++iter)
540  {
541  if (!other.found(iter.key()) && erase(iter))
542  {
543  ++changed;
544  }
545  }
546  }
547 
548  return changed;
549 }
550 
551 
552 template<class T, class Key, class Hash>
554 {
555  const label newCapacity = HashTableCore::canonicalSize(sz);
556  const label oldCapacity = capacity_;
557 
558  if (newCapacity == oldCapacity)
559  {
560  #ifdef FULLDEBUG
561  DebugInFunction << "New table size == old table size\n";
562  #endif
563 
564  return;
565  }
566  else if (!newCapacity)
567  {
568  // Special treatment for resize(0)
569  if (size_)
570  {
572  << "HashTable contains " << size_ << " cannot resize(0)" << nl;
573  }
574  else
575  {
576  if (table_)
577  {
578  delete[] table_;
579  capacity_ = 0;
580  }
581 
582  table_ = nullptr;
583  }
584 
585  return;
586  }
587 
588  // Swap primary table entries: size_ is left untouched
589 
590  auto oldTable = table_;
591  capacity_ = newCapacity;
592 
593  table_ = new node_type*[capacity_];
594  for (label i=0; i < capacity_; ++i)
595  {
596  table_[i] = nullptr;
597  }
598 
599  // Move to new table[] but with new chaining.
600 
601  label nMove = size_; // Allow early completion
602  for (label i=0; nMove && i < oldCapacity; ++i)
603  {
604  for (node_type* ep = oldTable[i]; ep; /*nil*/)
605  {
606  node_type* next = ep->next_;
607 
608  // Move to new location
609  {
610  const label newIdx = hashKeyIndex(ep->key());
611 
612  ep->next_ = table_[newIdx]; // add to head
613  table_[newIdx] = ep;
614  }
615 
616  ep = next; // continue in the linked-list
617  --nMove; // note any early completion
618  }
619  oldTable[i] = nullptr;
620  }
621 
622  if (oldTable)
623  {
624  delete[] oldTable;
625  }
626 }
627 
628 
629 template<class T, class Key, class Hash>
631 {
632  for (label i=0; size_ && i<capacity_; ++i)
633  {
634  for (node_type* ep = table_[i]; ep; /*nil*/)
635  {
636  node_type* next = ep->next_;
637 
638  delete ep;
639 
640  ep = next; // continue in the linked-list
641  --size_; // note any early completion
642  }
643  table_[i] = nullptr;
644  }
645 }
646 
647 
648 template<class T, class Key, class Hash>
650 {
651  clear();
652  resize(0);
653 }
654 
655 
656 template<class T, class Key, class Hash>
658 {
659  if (this == &rhs)
660  {
661  return; // Self-swap is a no-op
662  }
663 
664  std::swap(size_, rhs.size_);
665  std::swap(capacity_, rhs.capacity_);
666  std::swap(table_, rhs.table_);
667 }
668 
669 
670 template<class T, class Key, class Hash>
672 {
673  if (this == &rhs)
674  {
675  return; // Self-assignment is a no-op
676  }
677 
678  clear();
679  swap(rhs);
680 }
681 
682 
683 template<class T, class Key, class Hash>
684 template<class UnaryPredicate>
686 (
687  const UnaryPredicate& pred,
688  const bool pruning
689 )
690 {
691  label changed = 0;
692 
693  for (iterator iter = begin(); iter != end(); ++iter)
694  {
695  // Matches? either prune (pruning) or keep (!pruning)
696  if
697  (
698  (pred(iter.key()) ? pruning : !pruning)
699  && erase(iter)
700  )
701  {
702  ++changed;
703  }
704  }
705 
706  return changed;
707 }
708 
709 
710 template<class T, class Key, class Hash>
711 template<class UnaryPredicate>
713 (
714  const UnaryPredicate& pred,
715  const bool pruning
716 )
717 {
718  label changed = 0;
719 
720  for (iterator iter = begin(); iter != end(); ++iter)
721  {
722  // Matches? either prune (pruning) or keep (!pruning)
723  if
724  (
725  (pred(iter.val()) ? pruning : !pruning)
726  && erase(iter)
727  )
728  {
729  ++changed;
730  }
731  }
732 
733  return changed;
734 }
735 
736 
737 template<class T, class Key, class Hash>
738 template<class BinaryPredicate>
740 (
741  const BinaryPredicate& pred,
742  const bool pruning
743 )
744 {
745  label changed = 0;
746 
747  for (iterator iter = begin(); iter != end(); ++iter)
748  {
749  // Matches? either prune (pruning) or keep (!pruning)
750  if
751  (
752  (pred(iter.key(), iter.val()) ? pruning : !pruning)
753  && erase(iter)
754  )
755  {
756  ++changed;
757  }
758  }
759 
760  return changed;
761 }
762 
763 
764 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
765 
766 template<class T, class Key, class Hash>
768 (
769  const HashTable<T, Key, Hash>& rhs
770 )
771 {
772  if (this == &rhs)
773  {
774  return; // Self-assignment is a no-op
775  }
776 
777  if (!capacity_)
778  {
779  // Zero-sized from a previous transfer()?
780  resize(rhs.capacity_);
781  }
782  else
783  {
784  clear();
785  }
786 
787  for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
788  {
789  insert(iter.key(), iter.val());
790  }
791 }
792 
793 
794 template<class T, class Key, class Hash>
796 (
797  std::initializer_list<std::pair<Key, T>> rhs
798 )
799 {
800  if (!capacity_)
801  {
802  // Zero-sized from a previous transfer()?
803  resize(2*rhs.size());
804  }
805  else
806  {
807  clear();
808  }
809 
810  for (const auto& keyval : rhs)
811  {
812  set(keyval.first, keyval.second);
813  }
814 }
815 
816 
817 template<class T, class Key, class Hash>
819 (
821 )
822 {
823  if (this == &rhs)
824  {
825  return; // Self-assignment is a no-op
826  }
827 
828  transfer(rhs);
829 }
830 
831 
832 template<class T, class Key, class Hash>
834 (
835  const HashTable<T, Key, Hash>& rhs
836 ) const
837 {
838  // Sizes (number of keys) must match
839  if (size() != rhs.size())
840  {
841  return false;
842  }
843 
844  for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
845  {
846  const const_iterator other(this->cfind(iter.key()));
847 
848  if (!other.good() || other.val() != iter.val())
849  {
850  return false;
851  }
852  }
853 
854  return true;
855 }
856 
857 
858 template<class T, class Key, class Hash>
860 (
861  const HashTable<T, Key, Hash>& rhs
862 ) const
863 {
864  return !operator==(rhs);
865 }
866 
867 
868 template<class T, class Key, class Hash>
870 (
871  const HashTable<T, Key, Hash>& rhs
872 )
873 {
874  // Avoid no-ops:
875  if (rhs.size() || this != &rhs)
876  {
877  if (this->size())
878  {
879  for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
880  {
881  insert(iter.key(), iter.val());
882  }
883  }
884  else
885  {
886  (*this) = rhs;
887  }
888  }
889 
890  return *this;
891 }
892 
893 
894 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
895 
896 // Iterators, Friend Operators
897 
898 #include "HashTableIter.C"
899 #include "HashTableIO.C"
900 
901 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
902 
903 #endif
904 
905 // ************************************************************************* //
insert
srcOptions insert("case", fileName(rootDirSource/caseDirSource))
Foam::HashTable::size
label size() const noexcept
The number of elements in table.
Definition: HashTableI.H:52
Foam::BitOps::set
void set(List< bool > &bools, const labelRange &range)
Set the specified range 'on' in a boolList.
Definition: BitOps.C:37
List.H
stdFoam::begin
constexpr auto begin(C &c) -> decltype(c.begin())
Return iterator to the beginning of the container c.
Definition: stdFoam.H:97
HashTable.H
Foam::List::resize
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
Foam::FixedList::cend
const_iterator cend() const noexcept
Return const_iterator to end traversing the constant FixedList.
Definition: FixedListI.H:564
Foam::HashTable::toc
List< Key > toc() const
The table of contents (the keys) in unsorted order.
Definition: HashTable.C:121
Foam::HashTable::cbegin
const_iterator cbegin() const
const_iterator set to the beginning of the HashTable
Definition: HashTableIterI.H:248
Foam::HashTable::countEntries
label countEntries(const BinaryPredicate &pred, const bool invert=false) const
Count the number of entries that satisfy the binary predicate.
HashTableIter.C
Foam::glTF::key
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:108
Foam::HashTable::cend
constexpr const_iterator cend() const noexcept
const_iterator to signal the end (for any HashTable)
Definition: HashTableIterI.H:272
Foam::HashTable::countValues
label countValues(const UnaryPredicate &pred, const bool invert=false) const
Count the number of values that satisfy the unary predicate.
Foam::HashTable::filterValues
label filterValues(const UnaryPredicate &pred, const bool pruning=false)
Generalized means to filter table entries based on their values.
Foam::HashTable::tocKeys
List< Key > tocKeys(const UnaryPredicate &pred, const bool invert=false) const
erase
srcOptions erase("case")
Foam::HashTable::retain
label retain(const HashTable< AnyType, Key, AnyHash > &other)
Retain table entries given by keys of the other hash-table.
Foam::HashTable::countKeys
label countKeys(const UnaryPredicate &pred, const bool invert=false) const
Count the number of keys that satisfy the unary predicate.
Foam::invert
labelList invert(const label len, const labelUList &map)
Create an inverse one-to-one mapping.
Definition: ListOps.C:36
Foam::HashTable::filterEntries
label filterEntries(const BinaryPredicate &pred, const bool pruning=false)
Generalized means to filter table entries based on their key/value.
Foam::Hash
Hash function class. The default definition is for primitives. Non-primitives used to hash entries on...
Definition: Hash.H:53
Foam::UList::cend
const_iterator cend() const noexcept
Return const_iterator to end traversing the constant UList.
Definition: UListI.H:364
resize
patchWriters resize(patchIds.size())
Foam::operator==
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::HashTable::erase
bool erase(const iterator &iter)
Erase an entry specified by given iterator.
Definition: HashTable.C:392
DebugInFunction
#define DebugInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:388
Foam::sort
void sort(UList< T > &a)
Definition: UList.C:261
Foam::HashTable::resize
void resize(const label sz)
Resize the hash table for efficiency.
Definition: HashTable.C:553
Foam::HashTable::HashTable
HashTable()
Default construct with default (128) table capacity.
Definition: HashTable.C:39
Foam::HashTable::~HashTable
~HashTable()
Destructor.
Definition: HashTable.C:108
Foam::HashTable::tocEntries
List< Key > tocEntries(const BinaryPredicate &pred, const bool invert=false) const
Foam::HashTableCore
Bits that are independent of HashTable template parameters.
Definition: HashTableCore.H:56
Foam::HashTable::filterKeys
label filterKeys(const UnaryPredicate &pred, const bool pruning=false)
Generalized means to filter table entries based on their keys.
stdFoam::end
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:121
Foam::ListOps::find
label find(const ListType &input, const UnaryPredicate &pred, const label start=0)
Find index of the first occurrence that satisfies the predicate.
T
const volScalarField & T
Definition: createFieldRefs.H:2
stdFoam::cend
constexpr auto cend(const C &c) -> decltype(c.end())
Return const_iterator to the end of the container c.
Definition: stdFoam.H:137
Foam::HashTable::sortedToc
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
Definition: HashTable.C:136
Foam::HashTable::transfer
void transfer(HashTable< T, Key, Hash > &rhs)
Transfer contents into this table.
Definition: HashTable.C:671
Foam::HashTable::swap
void swap(HashTable< T, Key, Hash > &rhs)
Swap contents into this table.
Definition: HashTable.C:657
Foam::HashTable
A HashTable similar to std::unordered_map.
Definition: HashTable.H:105
Foam::UList::cbegin
const_iterator cbegin() const noexcept
Return const_iterator to begin traversing the constant UList.
Definition: UListI.H:343
Foam::HashTable::clearStorage
void clearStorage()
Clear the table entries and the table itself.
Definition: HashTable.C:649
clear
patchWriters clear()
Foam::nl
constexpr char nl
Definition: Ostream.H:404
stdFoam::cbegin
constexpr auto cbegin(const C &c) -> decltype(c.begin())
Return const_iterator to the beginning of the container c.
Definition: stdFoam.H:113
Foam::HashTable::clear
void clear()
Clear all entries from table.
Definition: HashTable.C:630
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::FixedList
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: HashTable.H:104
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
Foam::HashTable::tocValues
List< Key > tocValues(const UnaryPredicate &pred, const bool invert=false) const
Foam::FixedList::cbegin
const_iterator cbegin() const noexcept
Return const_iterator to begin traversing the constant FixedList.
Definition: FixedListI.H:540
Foam::HashTable::empty
bool empty() const noexcept
True if the hash table is empty.
Definition: HashTableI.H:59
FixedList.H
Foam::HashTable::found
bool found(const Key &key) const
Return true if hashed entry is found in table.
Definition: HashTableI.H:100
args
Foam::argList args(argc, argv)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
HashTableIO.C