hashedWordList.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) 2016-2022 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::hashedWordList
29
30Description
31 A wordList with hashed named lookup, which can be faster in some
32 situations than using the normal list find/found methods.
33
34SourceFiles
35 hashedWordListI.H
36 hashedWordList.C
37
38\*---------------------------------------------------------------------------*/
39
40#ifndef Foam_hashedWordList_H
41#define Foam_hashedWordList_H
42
43#include "wordList.H"
44#include "HashTable.H"
45
46// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47
48namespace Foam
49{
50
51/*---------------------------------------------------------------------------*\
52 Class hashedWordList Declaration
53\*---------------------------------------------------------------------------*/
56:
57 public wordList
58{
59 // Private Data
60
61 //- Lookup HashTable of words vs list-indices
62 mutable HashTable<label> lookup_;
63
64public:
65
66 // Constructors
67
68 //- Default construct an empty list
69 hashedWordList() = default;
70
71 //- Copy construct
72 inline hashedWordList(const hashedWordList& list);
73
74 //- Move construct
75 inline hashedWordList(hashedWordList&& list);
76
77 //- Copy construct from list of words
78 inline explicit hashedWordList(const wordUList& list);
79
80 //- Copy construct from list of words, eliminating duplicates
81 inline hashedWordList(const wordUList& list, bool unique);
82
83 //- Move construct from list of words, optionally eliminating duplicates
84 inline hashedWordList(wordList&& list, bool unique=false);
85
86 //- Construct from an initializer list
87 inline hashedWordList(std::initializer_list<word> list);
88
89 //- Construct from the word keys of any HashTable, sorting immediately.
90 // This also handles a wordHashSet, which is derived from a HashTable.
91 // The result is similar to a HashTable::sortedToc.
92 template<class AnyType, class AnyHash>
93 inline explicit hashedWordList
94 (
96 );
97
98 //- Construct from Istream
99 inline explicit hashedWordList(Istream& is);
100
101
102 // Member Functions
103
104 //- Clear the list, i.e. set size to zero.
105 inline void clear();
106
107 //- Append an element if not already in the list.
108 FOAM_DEPRECATED_FOR(2022-05, "appendUniq method")
109 inline void append(const word& val);
110
111 //- Append an element if not already in the list.
112 // \return the change in list length
113 inline label appendUniq(const word& val);
114
115 //- Return the hash of words/indices for inspection
116 inline const HashTable<label>& lookup() const;
117
118 //- Swap contents
119 inline void swap(hashedWordList& list);
120
121 //- Transfer contents of the argument into this list
122 //- and annul the argument list, optionally eliminating duplicates
123 inline void transfer(hashedWordList& list);
124
125 //- Transfer the contents of the argument List into this list
126 //- and annul the argument list, optionally eliminating duplicates
127 inline void transfer(wordList& list, bool unique=false);
128
129 //- Rebuild the lookup hash indices
130 void rehash() const;
131
132 //- Rebuild the lookup hash indices, or make unique entries first.
133 inline void rehash(bool unique);
134
135 //- Adjust the list (if needed) to eliminate duplicate entries,
136 //- and rehash the indices
137 void uniq();
138
139 //- Inplace sort list and rehash the indices
140 inline void sort();
141
142
143 // Search
144
145 //- Find index of the value (searches the hash).
146 // \return position in list or -1 if not found.
147 inline label find(const word& val) const;
148
149 //- True if the value if found in the list (searches the hash).
150 inline bool found(const word& val) const;
151
152
153 // Member Operators
154
155 //- Return name corresponding to specified index.
156 // Fatal for out of range values.
157 inline const word& operator[](const label index) const;
158
159 //- Find index of the value (searches the hash) - same as find().
160 // \return position in list or -1 if not found.
161 inline label operator[](const word& val) const;
162
163 //- Check hashed values for the specified name - same as found().
164 // Can be used as a unary predicate.
165 inline bool operator()(const word& val) const;
166
167
168 // Assignment
169
170 //- Copy assignment. Rehashes the indices.
171 inline void operator=(const hashedWordList& list);
172
173 //- Copy assignment from list of words. Rehashes the indices.
174 inline void operator=(const wordUList& list);
175
176 //- Copy assignment from initializer list. Rehashes the indices.
177 inline void operator=(std::initializer_list<word> list);
178
179 //- Move assignment operator.
180 inline void operator=(hashedWordList&& list);
181
182 //- Move assignment from list of words. Rehashes the indices.
183 inline void operator=(wordList&& list);
184
185
186 // Housekeeping
187
188 //- Deprecated(2019-01) Is the specified name found in the list?
189 // \deprecated(2019-01) - use found() method
190 FOAM_DEPRECATED_FOR(2019-01, "found() method")
191 bool contains(const word& val) const { return this->found(val); }
192};
193
194
195//- Read from an input stream. Rehashes the indices.
196inline Istream& operator>>(Istream& is, hashedWordList& list);
197
198
199// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
200
201} // End namespace Foam
202
203// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
204
205#include "hashedWordListI.H"
206
207#endif
208
209// ************************************************************************* //
bool found
A HashTable similar to std::unordered_map.
Definition: HashTable.H:123
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
A wordList with hashed named lookup, which can be faster in some situations than using the normal lis...
void transfer(hashedWordList &list)
label find(const word &val) const
Find index of the value (searches the hash).
hashedWordList()=default
Default construct an empty list.
void swap(hashedWordList &list)
Swap contents.
void sort()
Inplace sort list and rehash the indices.
void append(const word &val)
Append an element if not already in the list.
bool contains(const word &val) const
Deprecated(2019-01) Is the specified name found in the list?
void rehash() const
Rebuild the lookup hash indices.
void clear()
Clear the list, i.e. set size to zero.
label appendUniq(const word &val)
Append an element if not already in the list.
Lookup type of boundary radiation properties.
Definition: lookup.H:66
A class for handling words, derived from Foam::string.
Definition: word.H:68
Namespace for OpenFOAM.
Istream & operator>>(Istream &, directionInfo &)
#define FOAM_DEPRECATED_FOR(since, replacement)
Definition: stdFoam.H:52