HashList.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2022-2023 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::HashList
26 
27 Description
28  HashList class. Like HashTable, but much less dynamic memory-y. Should be
29  faster for small sets of non-dynamic primitive types (labels, edges,
30  points, etc...). It is also much less functional at present. There is no
31  re-sizing, so you have to make sure it is constructed sufficiently large to
32  hold all the data that will ever be inserted into it.
33 
34 SourceFiles
35  HashList.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #include "List.H"
40 #include "Tuple2.H"
41 #include "word.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 #ifndef HashList_H
46 #define HashList_H
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 /*---------------------------------------------------------------------------*\
54  Class HashList Declaration
55 \*---------------------------------------------------------------------------*/
56 
57 template<class Type, class Key=word, class Hash=string::hash>
58 class HashList
59 :
60  private List<Tuple2<Key, Type>>
61 {
62 public:
63 
64  // Public Static Member Data
65 
66  //- Null key value for unset elements in the list
67  static const Key nullKey;
68 
69 
70  // Constructors
71 
72  //- Construct given a size
73  HashList(const label size);
74 
75 
76  // Member Functions
77 
78  //- The size of the underlying list
79  inline label capacity() const;
80 
81  //- Clear all elements
82  void clear();
83 
84  //- Resize and clear all elements
85  void resizeAndClear(const label newSize);
86 
87  //- Insert into the hash list. Return true if the value was newly
88  // inserted, or false if it was already there.
89  bool insert(const Key& k, const Type& t);
90 
91 
92  // Member Operators
93 
94  //- Retrieve from the hash list
95  const Type& operator[](const Key& k) const;
96 };
97 
98 
99 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
100 
101 } // End namespace Foam
102 
103 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
104 
105 #ifdef NoRepository
106  #include "HashList.C"
107 #endif
108 
109 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
110 
111 #endif
112 
113 // ************************************************************************* //
label k
HashList class. Like HashTable, but much less dynamic memory-y. Should be faster for small sets of no...
Definition: HashList.H:60
HashList(const label size)
Construct given a size.
Definition: HashList.C:40
void resizeAndClear(const label newSize)
Resize and clear all elements.
Definition: HashList.C:66
label capacity() const
The size of the underlying list.
Definition: HashList.C:49
const Type & operator[](const Key &k) const
Retrieve from the hash list.
Definition: HashList.C:112
bool insert(const Key &k, const Type &t)
Insert into the hash list. Return true if the value was newly.
Definition: HashList.C:77
static const Key nullKey
Null key value for unset elements in the list.
Definition: HashList.H:66
void clear()
Clear all elements.
Definition: HashList.C:56
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
label size() const
Return the number of elements in the UList.
Definition: ListI.H:171
Namespace for OpenFOAM.
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:59