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 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 {};
69
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
96
97 // Data
98
99 //- The lookup key
100 const K key_;
101
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
117
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 - for pointer types
169 template<class TypeT = V>
170 typename std::enable_if
171 <
172 (
173 std::is_pointer<TypeT>::value
175 ),
176 void
178 print(Ostream& os) const
179 {
180 os << key_;
181
182 if (val_)
183 {
184 os << ' ' << *val_;
185 }
186 }
187
188 //- Write (key, val) pair - for non-pointer types
189 template<class TypeT = V>
190 typename std::enable_if
191 <
192 (
193 !std::is_pointer<TypeT>::value
195 ),
196 void
198 print(Ostream& os) const
199 {
200 os << key_ << ' ' << val_;
201 }
202};
203
204
205/*---------------------------------------------------------------------------*\
206 Class HashTableSingle Declaration
207\*---------------------------------------------------------------------------*/
208
209//- Internal storage type for HashSet entries
210// Comprises a single (K) value and a linked-list entry for hash collisions
211template<class K>
212struct HashTableSingle
213{
214 // Data Types
215
216 //- Type of key
217 typedef K key_type;
218
219 //- Type of content (no content: placeholder)
221
222 //- Content storage type to the entry
223 typedef key_type value_type;
224
225 //- This class does not store any value
226 static constexpr bool stores_value() noexcept
227 {
228 return false;
229 }
230
231
232 // Data
233
234 //- The lookup key == content
235 const K key_;
236
237 //- Addressing (next in collision list)
239
240
241 // Generated Methods
242
243 //- No copy construct
244 HashTableSingle(const HashTableSingle&) = delete;
245
246 //- No copy assignment
247 void operator=(const HashTableSingle&) = delete;
248
249
250 // Constructors
251
252 //- Construct from next pointer, key, (unused) contents
253 template<class... Args>
255 (
256 HashTableSingle* next,
257 const key_type& key,
258 Args&&...
259 )
260 :
261 key_(key),
262 next_(next)
263 {}
264
265
266 // Member Functions
267
268 //- The key
269 const key_type& key() const noexcept
270 {
271 return key_;
272 }
273
274 //- Const access to the (dummy) mapped value
275 const mapped_type& cval() const noexcept
276 {
278 }
279
280 //- Const access to the (dummy) mapped value
281 const mapped_type& val() const noexcept
282 {
284 }
285
286 //- Non-const access to the (dummy) mapped value
288 {
290 }
291
292
293 //- Compare keys
294 bool operator<(const HashTableSingle& rhs) const
295 {
296 return key_ < rhs.key_;
297 }
298
299 //- Write the key. There is no value to write.
300 void print(Ostream& os) const
301 {
302 os << key_;
303 }
304};
305
306
307// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
308
309} // End namespace Detail
310} // End namespace Foam
311
312// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
313
314#endif
315
316// ************************************************************************* //
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:62
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A zero class with a null output adapter.
Definition: zero.H:112
static null dummy
A static zero::null for dereferencing as a dummy element.
Definition: zero.H:118
const volScalarField & T
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
const direction noexcept
Definition: Scalar.H:223
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.
std::enable_if<(!std::is_pointer< TypeT >::value &&!Detail::isPointerLike< TypeT >::value), void >::type print(Ostream &os) const
Write (key, val) pair - for non-pointer types.
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.
std::enable_if<(std::is_pointer< TypeT >::value||Detail::isPointerLike< TypeT >::value), void >::type print(Ostream &os) const
Write (key, val) pair - for pointer types.
bool operator<(const HashTablePair &rhs) const
Compare keys.
Internal storage type for HashSet entries.
Foam::zero::null mapped_type
Type of content (no content: placeholder)
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.
key_type value_type
Content storage type to the entry.
mapped_type & val() noexcept
Non-const access to the (dummy) mapped value.
const K key_
The lookup key == content.
const mapped_type & val() const noexcept
Const access to the (dummy) mapped value.
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.
bool operator<(const HashTableSingle &rhs) const
Compare keys.
Pointer-like behaviour.