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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
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_.reserve(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_.reserve(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 size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
void rehash() const
Rebuild the lookup hash indices.
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
Definition: HashTableI.H:152
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of &#39;true&#39; entries.
Definition: BitOps.H:73
void clear()
Remove all entries from table.
Definition: HashTable.C:725
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:105
List< word > wordList
List of word.
Definition: fileName.H:59
void reserve(label numEntries)
Reserve space for at least the specified number of elements (not the number of buckets) and regenerat...
Definition: HashTable.C:712
void uniq()
Adjust the list (if needed) to eliminate duplicate entries, and rehash the indices.