Loading...
Searching...
No Matches
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-2025 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::HashTableCore
29
30Description
31 Template invariant parts of hash table implementation.
32
33SourceFiles
34 HashTableCore.C
35
36\*---------------------------------------------------------------------------*/
37
38#ifndef Foam_HashTableCore_H
39#define Foam_HashTableCore_H
40
41#include "label.H"
42#include "className.H"
43#include "nullObject.H"
44
45// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46
47namespace Foam
48{
49
50/*---------------------------------------------------------------------------*\
51 Class HashTableCore Declaration
52\*---------------------------------------------------------------------------*/
53
54//- Bits that are independent of HashTable template parameters.
55struct HashTableCore
56{
57 //- Maximum allowable internal table size (must be a power of two!).
58 // - approximately (INT32_MAX/4) => 0x20000000
59 // - don't need an int64 version
60 static constexpr int32_t maxTableSize = (1 << (32-3));
61
62 //- Return a canonical (power-of-two) of the requested size.
63 static label canonicalSize(const label size) noexcept;
64
65 //- Declare type-name (with debug switch)
66 ClassName("HashTable");
67
68 //- Default construct
69 constexpr HashTableCore() noexcept = default;
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 //- type, normally associated with a HashTable.
80 // Uses begin iterator and size for bookkeeping.
81 template<class IteratorType, class TableType>
83 {
84 const label size_;
85 IteratorType iter_;
86
87 public:
88
89 //- Default construct an empty pair
91 :
92 size_(0),
93 iter_()
94 {}
95
96 //- Construct begin/end pair for table
97 const_iterator_pair(const TableType& tbl)
98 :
99 size_(tbl.size()),
100 iter_(tbl.begin())
101 {}
102
103 bool empty() const noexcept { return !size_; }
104 label size() const noexcept { return size_; }
105
106 IteratorType begin() const noexcept { return iter_; }
107 IteratorType cbegin() const noexcept { return iter_; }
108
109 IteratorType end() const { return IteratorType(); }
110 IteratorType cend() const { return IteratorType(); }
111 };
112};
113
114
115// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
117} // End namespace Foam
118
119// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
121#endif
123// ************************************************************************* //
Factory class for creating a begin/end pair for any const iterator type, normally associated with a H...
const_iterator_pair()
Default construct an empty pair.
const_iterator_pair(const TableType &tbl)
Construct begin/end pair for table.
IteratorType begin() const noexcept
IteratorType cbegin() const noexcept
Singleton null-object class and instance.
Definition nullObject.H:57
Macro definitions for declaring ClassName(), NamespaceName(), etc.
#define ClassName(TypeNameString)
Add typeName information from argument TypeNameString to a class.
Definition className.H:74
const char * end
Definition SVGTools.H:223
Namespace for OpenFOAM.
const direction noexcept
Definition scalarImpl.H:265
static constexpr int32_t maxTableSize
Maximum allowable internal table size (must be a power of two!).
constexpr HashTableCore() noexcept=default
Default construct.
static label canonicalSize(const label size) noexcept
Return a canonical (power-of-two) of the requested size.
ClassName("HashTable")
Declare type-name (with debug switch).