hashedWordList.C
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) 2011-2019 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 \*---------------------------------------------------------------------------*/
25 
26 #include "hashedWordList.H"
27 
28 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
29 
30 void Foam::hashedWordList::rehash()
31 {
32  indices_.clear();
33  forAll(*this, i)
34  {
35  indices_.insert(List<word>::operator[](i), i);
36  }
37 }
38 
39 
40 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41 
43 :
44  List<word>()
45 {}
46 
47 
49 :
50  List<word>(names)
51 {
52  rehash();
53 }
54 
55 
57 :
58  List<word>(static_cast<const UList<word>&>(names))
59 {
60  rehash();
61 }
62 
63 
65 :
66  List<word>(move(names)),
67  indices_(move(names.indices_))
68 {}
69 
70 
72 :
73  List<word>(move(names))
74 {
75  rehash();
76 }
77 
78 
80 (
81  const label nNames,
82  const char** names
83 )
84 :
85  List<word>(nNames)
86 {
87  forAll(*this, i)
88  {
89  List<word>::operator[](i) = names[i];
90  }
91 
92  rehash();
93 }
94 
95 
97 (
98  const char** names
99 )
100 {
101  // count names
102  label nNames = 0;
103  for (unsigned i = 0; names[i] && *(names[i]); ++i)
104  {
105  ++nNames;
106  }
107 
108  List<word>::setSize(nNames);
109  forAll(*this, i)
110  {
111  List<word>::operator[](i) = names[i];
112  }
113 
114  rehash();
115 }
116 
117 
119 {
120  is >> *this;
121 }
122 
123 
124 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
125 
127 {
129  indices_.clear();
130 }
131 
132 
134 {
135  const label idx = size();
136  List<word>::append(name);
137  indices_.insert(name, idx);
138 }
139 
140 
142 {
144  rehash();
145 }
146 
147 
148 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
149 
151 {
152  is >> static_cast<List<word>&>(lst);
153  lst.rehash();
154 
155  return is;
156 }
157 
158 
160 {
161  os << static_cast<const List<word>&>(lst);
162  return os;
163 }
164 
165 
166 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
friend Ostream & operator(Ostream &, const UList< T > &)
T & operator[](const label)
Return element of UList.
Definition: UListI.H:167
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:124
A class for handling words, derived from string.
Definition: word.H:59
Istream & operator>>(Istream &, directionInfo &)
void append(const T &)
Append an element at the end of the list.
Definition: ListI.H:177
void transfer(List< word > &)
Transfer the contents of the argument List into this list.
void append(const word &)
Append an element at the end of the list.
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:60
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
void clear()
Clear the list, i.e. set size to zero.
void setSize(const label)
Reset size of List.
Definition: List.C:281
A wordList with hashed indices for faster lookup by name.
Ostream & operator<<(Ostream &, const ensightPart &)
label size() const
Return the number of elements in the UList.
Definition: ListI.H:170
hashedWordList()
Construct null.
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342