HashTableCore.H
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-2020 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 Class
28  Foam::HashTableCore
29 
30 Description
31  Template invariant parts of hash table implementation.
32 
33 SourceFiles
34  HashTableCoreI.H
35  HashTableCore.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef HashTableCore_H
40 #define HashTableCore_H
41 
42 #include "label.H"
43 #include "uLabel.H"
44 #include "className.H"
45 #include "nullObject.H"
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 /*---------------------------------------------------------------------------*\
53  Class HashTableCore Declaration
54 \*---------------------------------------------------------------------------*/
55 
56 //- Bits that are independent of HashTable template parameters.
57 struct HashTableCore
58 {
59  //- Maximum allowable internal table size. Approximately labelMax/4
60  static const label maxTableSize;
61 
62  //- Return a canonical (power-of-two) of the requested size.
63  static label canonicalSize(const label requested_size);
64 
65  //- Declare type-name (with debug switch)
66  ClassName("HashTable");
67 
68  //- Default construct
69  HashTableCore() = default;
70 
71  static_assert
72  (
73  sizeof(NullObject) >= sizeof(void*),
74  "NullObject is too small to reinterpret_cast as HashTable::iterator"
75  );
76 
77 
78  //- Factory class for creating a begin/end pair for any const iterator.
79  template<class IteratorType, class TableType>
81  {
82  const label size_;
83  IteratorType iter_;
84 
85  public:
86 
87  //- Default construct an empty pair
88  inline const_iterator_pair();
89 
90  //- Construct begin/end pair for table
91  inline const_iterator_pair(const TableType& tbl);
92 
93  label size() const noexcept { return size_; }
94  bool empty() const noexcept { return !size_; }
95 
96  inline IteratorType begin() const;
97  inline IteratorType cbegin() const;
98 
99  inline IteratorType end() const;
100  inline IteratorType cend() const;
101  };
102 };
103 
104 
105 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
106 
107 } // End namespace Foam
108 
109 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
110 
111 #include "HashTableCoreI.H"
112 
113 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
114 
115 #endif
116 
117 // ************************************************************************* //
HashTableCoreI.H
Foam::HashTableCore::const_iterator_pair::const_iterator_pair
const_iterator_pair()
Default construct an empty pair.
Definition: HashTableCoreI.H:32
className.H
Macro definitions for declaring ClassName(), NamespaceName(), etc.
Foam::HashTableCore::canonicalSize
static label canonicalSize(const label requested_size)
Return a canonical (power-of-two) of the requested size.
Definition: HashTableCore.C:45
Foam::HashTableCore::const_iterator_pair::cend
IteratorType cend() const
Definition: HashTableCoreI.H:89
Foam::HashTableCore
Bits that are independent of HashTable template parameters.
Definition: HashTableCore.H:56
Foam::HashTableCore::HashTableCore
HashTableCore()=default
Default construct.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::HashTableCore::const_iterator_pair
Factory class for creating a begin/end pair for any const iterator.
Definition: HashTableCore.H:79
Foam::HashTableCore::maxTableSize
static const label maxTableSize
Maximum allowable internal table size. Approximately labelMax/4.
Definition: HashTableCore.H:59
Foam::HashTableCore::const_iterator_pair::end
IteratorType end() const
Definition: HashTableCoreI.H:78
label.H
Foam::NullObject
Singleton null-object class and instance.
Definition: nullObject.H:60
Foam::HashTableCore::const_iterator_pair::cbegin
IteratorType cbegin() const
Definition: HashTableCoreI.H:67
nullObject.H
Foam::HashTableCore::const_iterator_pair::begin
IteratorType begin() const
Definition: HashTableCoreI.H:56
uLabel.H
Foam::HashTableCore::const_iterator_pair::size
label size() const noexcept
Definition: HashTableCore.H:92
Foam::HashTableCore::const_iterator_pair::empty
bool empty() const noexcept
Definition: HashTableCore.H:93
Foam::HashTableCore::ClassName
ClassName("HashTable")
Declare type-name (with debug switch)