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-2019 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  //- Construct null
66  HashTableCore() = default;
67 
68  //- Define template name and debug
69  ClassName("HashTable");
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 method to create a non-const iterator begin
79  template<class IteratorType, class TableType>
80  inline static IteratorType iterator_begin(TableType& table);
81 
82  //- Factory method to create a const iterator begin
83  template<class IteratorType, class TableType>
84  inline static IteratorType iterator_cbegin(const TableType& table);
85 
86  //- Factory method to return an iterator end
87  // Simply reinterprets a NullObject as a hash-table iterator.
88  template<class IteratorType>
89  inline static const IteratorType& iterator_end();
90 
91  //- Factory method to return an iterator cend
92  // Simply reinterprets a NullObject as a hash-table iterator.
93  template<class IteratorType>
94  inline static const IteratorType& iterator_cend();
95 
96 
97  //- Factory class for creating a begin/end pair for any const iterator.
98  template<class IteratorType, class TableType>
100  {
101  label size_;
102  IteratorType iter_;
103 
104  public:
105 
106  inline const_iterator_pair(const TableType& tbl);
107 
108  label size() const noexcept { return size_; }
109  bool empty() const noexcept { return !size_; }
110 
111  inline IteratorType begin() const;
112  inline IteratorType cbegin() const;
113 
114  inline const IteratorType& end() const;
115  inline const IteratorType& cend() const;
116  };
117 };
118 
119 
120 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
121 
122 } // End namespace Foam
123 
124 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
125 
126 #include "HashTableCoreI.H"
127 
128 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
129 
130 #endif
131 
132 // ************************************************************************* //
Foam::HashTableCore::const_iterator_pair::const_iterator_pair
const_iterator_pair(const TableType &tbl)
Definition: HashTableCoreI.H:69
Foam::HashTableCore::const_iterator_pair::cend
const IteratorType & cend() const
Definition: HashTableCoreI.H:116
Foam::HashTableCore::const_iterator_pair::end
const IteratorType & end() const
Definition: HashTableCoreI.H:105
Foam::HashTableCore::iterator_cend
static const IteratorType & iterator_cend()
Factory method to return an iterator cend.
Definition: HashTableCoreI.H:58
HashTableCoreI.H
Foam::HashTableCore::iterator_begin
static IteratorType iterator_begin(TableType &table)
Factory method to create a non-const iterator begin.
Definition: HashTableCoreI.H:32
Foam::HashTableCore::iterator_end
static const IteratorType & iterator_end()
Factory method to return an iterator end.
Definition: HashTableCoreI.H:51
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
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
Bits that are independent of HashTable template parameters.
Definition: HashTableCore.H:56
Foam::HashTableCore::HashTableCore
HashTableCore()=default
Construct null.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::HashTableCore::iterator_cbegin
static IteratorType iterator_cbegin(const TableType &table)
Factory method to create a const iterator begin.
Definition: HashTableCoreI.H:42
Foam::HashTableCore::const_iterator_pair
Factory class for creating a begin/end pair for any const iterator.
Definition: HashTableCore.H:98
Foam::HashTableCore::maxTableSize
static const label maxTableSize
Maximum allowable internal table size. Approximately labelMax/4.
Definition: HashTableCore.H:59
label.H
Foam::NullObject
Singleton null-object class and instance.
Definition: nullObject.H:58
Foam::HashTableCore::const_iterator_pair::cbegin
IteratorType cbegin() const
Definition: HashTableCoreI.H:94
nullObject.H
Foam::HashTableCore::const_iterator_pair::begin
IteratorType begin() const
Definition: HashTableCoreI.H:83
uLabel.H
Foam::HashTableCore::const_iterator_pair::size
label size() const noexcept
Definition: HashTableCore.H:107
Foam::HashTableCore::const_iterator_pair::empty
bool empty() const noexcept
Definition: HashTableCore.H:108
Foam::HashTableCore::ClassName
ClassName("HashTable")
Define template name and debug.