The open source CFD toolbox
hashedWordList.C
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) 2016-2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
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
26\*---------------------------------------------------------------------------*/
27
28#include "hashedWordList.H"
29
30// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
31
33{
34 const wordUList& list = *this;
35 const label len = list.size();
36
37 lookup_.clear();
38 lookup_.resize(2*len);
39
40 for (label i = 0; i < len; ++i)
41 {
42 lookup_.insert(list[i], i);
43 }
44}
45
46
48{
49 wordList& list = *this;
50 const label len = list.size();
51
52 lookup_.clear();
53 lookup_.resize(2*len);
54
55 label count = 0;
56
57 for (label i = 0; i < len; ++i)
58 {
59 word& item = list[i];
60
61 if (lookup_.insert(item, i))
62 {
63 if (count != i)
64 {
65 list[count] = std::move(item);
66 }
67 ++count;
68 }
69 }
70
71 list.resize(count);
72}
73
74
75// ************************************************************************* //
void resize(const label sz)
Resize the hash table for efficiency.
Definition: HashTable.C:601
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
Definition: HashTableI.H:180
void clear()
Clear all entries from table.
Definition: HashTable.C:678
void resize(const label len)
Definition: ListI.H:139
void size(const label n)
Definition: UList.H:114
void rehash() const
Rebuild the lookup hash indices.
A class for handling words, derived from Foam::string.
Definition: word.H:68