Loading...
Searching...
No Matches
HashTableDetail.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) 2019-2025 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Class
27 Foam::Detail::HashTablePair
28
29Description
30 Internal storage type for HashTable
31
32SourceFiles
33 HashTableDetail.H
34
35\*---------------------------------------------------------------------------*/
36
37#ifndef Foam_HashTableDetail_H
38#define Foam_HashTableDetail_H
39
40#include "zero.H"
41#include <memory>
42#include <utility>
43#include <type_traits>
44
45// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46
47namespace Foam
48{
49
50// Forward Declarations
51class Ostream;
52template<class T> class autoPtr;
53
54namespace Detail
55{
56
57/*---------------------------------------------------------------------------*\
58 Class isPointerLike Declaration
59\*---------------------------------------------------------------------------*/
60
61//- Pointer-like behaviour
62template<class T> struct isPointerLike : std::false_type {};
63
64//- Pointer-like behaviour for autoPtr
65template<class T> struct isPointerLike<autoPtr<T>> : std::true_type {};
66
67//- Pointer-like behaviour for std::unique_ptr
68template<class T> struct isPointerLike<std::unique_ptr<T>> : std::true_type {};
70
71/*---------------------------------------------------------------------------*\
72 Class HashTablePair Declaration
73\*---------------------------------------------------------------------------*/
74
75//- Internal storage type for HashTable entries
76// Comprises a (K,V) tuple and a linked-list entry for hash collisions.
77// Could store key/val as std::pair, but no particular advantage
78// unless the iterator dereference type changes.
79template<class K, class V>
80struct HashTablePair
81{
82 // Data Types
83
84 //- Type of key
85 typedef K key_type;
86
87 //- Type of content
88 typedef V mapped_type;
89
90 //- This class stores a value
91 static constexpr bool stores_value() noexcept
92 {
93 return true;
94 }
95
97 // Data
98
99 //- The lookup key
100 const K key_;
102 //- The mapped data
103 V val_;
104
105 //- Addressing (next in collision list)
107
108
109 // Generated Methods
110
111 //- No copy construct
112 HashTablePair(const HashTablePair&) = delete;
113
114 //- No copy assignment
115 void operator=(const HashTablePair&) = delete;
116
118 // Constructors
119
120 //- Construct from next pointer, key, contents
121 template<class... Args>
123 (
124 HashTablePair* next,
125 const key_type& key,
126 Args&&... args
127 )
128 :
129 key_(key),
130 val_(std::forward<Args>(args)...),
131 next_(next)
132 {}
133
134
135 // Member Functions
136
137 //- The key
138 const key_type& key() const noexcept
139 {
140 return key_;
141 }
142
143 //- Const access to the mapped value
144 const mapped_type& cval() const noexcept
145 {
146 return val_;
147 }
148
149 //- Const access to the mapped value
150 const mapped_type& val() const noexcept
151 {
152 return val_;
153 }
154
155 //- Non-const access to the mapped value
157 {
158 return val_;
159 }
160
161
162 //- Compare keys
163 bool operator<(const HashTablePair& rhs) const
164 {
165 return key_ < rhs.key_;
166 }
167
168 //- Write (key, val) pair
169 void print(Ostream& os) const
171 os << key_;
172
173 if constexpr
174 (
175 std::is_pointer_v<V>
177 )
179 // Pointer or pointer-like types
180 if (val_)
181 {
182 os << ' ' << *val_;
183 }
184 }
185 else
187 // Non-pointer types
188 os << ' ' << val_;
189 }
190 }
191};
192
193
194/*---------------------------------------------------------------------------*\
195 Class HashTableSingle Declaration
196\*---------------------------------------------------------------------------*/
197
198//- Internal storage type for HashSet entries
199// Comprises a single (K) value and a linked-list entry for hash collisions
200template<class K>
201struct HashTableSingle
202{
203 // Data Types
204
205 //- Type of key
206 typedef K key_type;
207
208 //- Type of content (no content: placeholder)
209 typedef Foam::zero mapped_type;
210
211 //- Content storage type to the entry
212 typedef key_type value_type;
213
214 //- This class does not store any value
215 static constexpr bool stores_value() noexcept
216 {
217 return false;
218 }
219
220
221 // Data
222
223 //- The lookup key == content
224 const K key_;
225
226 //- Addressing (next in collision list)
228
229
230 // Generated Methods
231
232 //- No copy construct
233 HashTableSingle(const HashTableSingle&) = delete;
234
235 //- No copy assignment
236 void operator=(const HashTableSingle&) = delete;
237
239 // Constructors
240
241 //- Construct from next pointer, key, (unused) contents
242 template<class... Args>
244 (
246 const key_type& key,
247 Args&&...
248 )
249 :
251 next_(next)
252 {}
253
254
255 // Member Functions
256
257 //- The key
258 const key_type& key() const noexcept
259 {
260 return key_;
261 }
262
263 //- Const access to the (dummy) mapped value (for API only)
264 const mapped_type& cval() const noexcept
265 {
266 return Foam::zero::dummy;
267 }
268
269 //- Const access to the (dummy) mapped value (for API only)
270 const mapped_type& val() const noexcept
272 return Foam::zero::dummy;
273 }
274
275 //- Non-const access to the (dummy) mapped value (for API only)
277 {
278 return Foam::zero::dummy;
279 }
280
281
282 //- Compare keys
283 bool operator<(const HashTableSingle& rhs) const
285 return key_ < rhs.key_;
286 }
287
288 //- Write the key. There is no value to write.
289 void print(Ostream& os) const
290 {
291 os << key_;
292 }
293};
294
295
296// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
297
298} // End namespace Detail
299} // End namespace Foam
300
301// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
302
303#endif
304
305// ************************************************************************* //
CGAL::Exact_predicates_exact_constructions_kernel K
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition zero.H:58
static zero dummy
A static instance, when modifiable reference is required by an API.
Definition zero.H:69
OBJstream os(runTime.globalPath()/outputName)
Implementation details for various OpenFOAM classes.
Definition zoneSubSet.C:30
Namespace for OpenFOAM.
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
const direction noexcept
Definition scalarImpl.H:265
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Foam::argList args(argc, argv)
Internal storage type for HashTable entries.
V mapped_type
Type of content.
HashTablePair(const HashTablePair &)=delete
No copy construct.
const mapped_type & cval() const noexcept
Const access to the mapped value.
mapped_type & val() noexcept
Non-const access to the mapped value.
const K key_
The lookup key.
const mapped_type & val() const noexcept
Const access to the mapped value.
void operator=(const HashTablePair &)=delete
No copy assignment.
void print(Ostream &os) const
Write (key, val) pair.
const key_type & key() const noexcept
The key.
HashTablePair * next_
Addressing (next in collision list).
static constexpr bool stores_value() noexcept
This class stores a value.
HashTablePair(HashTablePair *next, const key_type &key, Args &&... args)
Construct from next pointer, key, contents.
bool operator<(const HashTablePair &rhs) const
Compare keys.
Internal storage type for HashSet entries.
HashTableSingle(const HashTableSingle &)=delete
No copy construct.
void operator=(const HashTableSingle &)=delete
No copy assignment.
HashTableSingle * next_
Addressing (next in collision list).
const mapped_type & cval() const noexcept
Const access to the (dummy) mapped value (for API only).
key_type value_type
Content storage type to the entry.
mapped_type & val() noexcept
Non-const access to the (dummy) mapped value (for API only).
const K key_
The lookup key == content.
const mapped_type & val() const noexcept
Const access to the (dummy) mapped value (for API only).
HashTableSingle(HashTableSingle *next, const key_type &key, Args &&...)
Construct from next pointer, key, (unused) contents.
void print(Ostream &os) const
Write the key. There is no value to write.
const key_type & key() const noexcept
The key.
static constexpr bool stores_value() noexcept
This class does not store any value.
Foam::zero mapped_type
Type of content (no content: placeholder).
bool operator<(const HashTableSingle &rhs) const
Compare keys.
Pointer-like behaviour.