PackedBoolList.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) 2011-2021 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::PackedBoolList
26 
27 Description
28  A bit-packed bool list.
29 
30  In addition to the obvious memory advantage over using a
31  List<bool>, this class also provides a number of bit-like
32  operations.
33 
34 SourceFiles
35  PackedBoolListI.H
36  PackedBoolList.C
37 
38 See also
39  Foam::PackedList
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #ifndef PackedBoolList_H
44 #define PackedBoolList_H
45 
46 #include "PackedList.H"
47 #include "UIndirectList.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 // Forward declaration
55 class PackedBoolList;
56 
57 //- \typedef A List of PackedBoolList
59 
60 /*---------------------------------------------------------------------------*\
61  Class PackedBoolList Declaration
62 \*---------------------------------------------------------------------------*/
63 
64 class PackedBoolList
65 :
66  public PackedList<1>
67 {
68  // Private Member Functions
69 
70  //- Preparation, resizing before a bitor operation
71  // returns true if the later result needs trimming
72  bool bitorPrepare(const PackedList<1>& lst, label& maxPackLen);
73 
74  //- Set the listed indices. Return number of elements changed.
75  // Does auto-vivify for non-existent entries.
76  template<class LabelListType>
77  label setIndices(const LabelListType& indices);
78 
79  //- Unset the listed indices. Return number of elements changed.
80  // Never auto-vivify entries.
81  template<class LabelListType>
82  label unsetIndices(const LabelListType& indices);
83 
84  //- Subset with the listed indices. Return number of elements subsetted.
85  template<class LabelListType>
86  label subsetIndices(const LabelListType& indices);
87 
88 
89 public:
90 
91  // Constructors
92 
93  //- Construct null
94  inline PackedBoolList();
95 
96  //- Construct from Istream
98 
99  //- Construct with given size, initialises list to 0
100  explicit inline PackedBoolList(const label size);
101 
102  //- Construct with given size and value for all elements
103  inline PackedBoolList(const label size, const bool val);
104 
105  //- Copy constructor
106  inline PackedBoolList(const PackedBoolList&);
107 
108  //- Copy constructor
109  explicit inline PackedBoolList(const PackedList<1>&);
110 
111  //- Construct from a list of bools
112  explicit inline PackedBoolList(const Foam::UList<bool>&);
113 
114  //- Construct from a list of labels
115  // using the labels as indices to indicate which bits are set
116  explicit inline PackedBoolList(const labelUList& indices);
117 
118  //- Construct from a list of labels
119  // using the labels as indices to indicate which bits are set
120  explicit inline PackedBoolList(const UIndirectList<label>& indices);
121 
122  //- Clone
123  inline autoPtr<PackedBoolList> clone() const;
124 
125 
126  // Member Functions
127 
128  // Access
129 
130  using PackedList<1>::set;
131  using PackedList<1>::unset;
132 
133  //- Set specified bits.
134  void set(const PackedList<1>&);
135 
136  //- Set the listed indices. Return number of elements changed.
137  // Does auto-vivify for non-existent entries.
138  label set(const labelUList& indices);
139 
140  //- Set the listed indices. Return number of elements changed.
141  // Does auto-vivify for non-existent entries.
142  label set(const UIndirectList<label>& indices);
143 
144  //- Unset specified bits.
145  void unset(const PackedList<1>&);
146 
147  //- Unset the listed indices. Return number of elements changed.
148  // Never auto-vivify entries.
149  label unset(const labelUList& indices);
150 
151  //- Unset the listed indices. Return number of elements changed.
152  // Never auto-vivify entries.
153  label unset(const UIndirectList<label>& indices);
154 
155  //- Subset with the specified list.
156  void subset(const PackedList<1>&);
157 
158  //- Subset with the listed indices.
159  // Return number of elements subsetted.
160  label subset(const labelUList& indices);
161 
162  //- Subset with the listed indices.
163  // Return number of elements subsetted.
164  label subset(const UIndirectList<label>& indices);
165 
166  //- Return indices of the used (true) elements as a list of labels
167  labelList used() const;
168 
169 
170  // Edit
171 
172  //- Transfer the contents of the argument list into this list
173  // and annul the argument list.
174  inline void transfer(PackedBoolList&);
175 
176  //- Transfer the contents of the argument list into this list
177  // and annul the argument list.
178  inline void transfer(PackedList<1>&);
179 
180 
181  // Member Operators
182 
183  //- Assignment of all entries to the given value.
184  inline void operator=(const bool val);
185 
186  //- Assignment operator.
187  inline void operator=(const PackedBoolList&);
188 
189  //- Assignment operator.
190  inline void operator=(const PackedList<1>&);
191 
192  //- Assignment operator.
193  void operator=(const Foam::UList<bool>&);
194 
195  //- Assignment operator,
196  // using the labels as indices to indicate which bits are set
197  inline void operator=(const labelUList& indices);
198 
199  //- Assignment operator,
200  // using the labels as indices to indicate which bits are set
201  inline void operator=(const UIndirectList<label>&);
202 
203  //- Complement operator
204  inline PackedBoolList operator~() const;
205 
206  //- And operator (lists may be dissimilar sizes)
207  inline PackedBoolList& operator&=(const PackedList<1>&);
208 
209  //- And operator (lists may be dissimilar sizes)
210  // using the labels as indices to indicate which bits are set
211  inline PackedBoolList& operator&=(const labelUList& indices);
212 
213  //- And operator (lists may be dissimilar sizes)
214  // using the labels as indices to indicate which bits are set
216 
217  //- Xor operator (lists may be dissimilar sizes)
218  // Retains unique entries
220 
221  //- Or operator (lists may be dissimilar sizes)
222  inline PackedBoolList& operator|=(const PackedList<1>&);
223 
224  //- Or operator (lists may be dissimilar sizes),
225  // using the labels as indices to indicate which bits are set
226  inline PackedBoolList& operator|=(const labelUList& indices);
227 
228  //- Or operator (lists may be dissimilar sizes),
229  // using the labels as indices to indicate which bits are set
231 
232 
233  //- Add entries to this list, synonymous with the or operator
234  inline PackedBoolList& operator+=(const PackedList<1>&);
235 
236  //- Add entries to this list, synonymous with the or operator
237  inline PackedBoolList& operator+=(const labelUList& indices);
238 
239  //- Add entries to this list, synonymous with the or operator
241 
242  //- Remove entries from this list - unset the specified bits
243  inline PackedBoolList& operator-=(const PackedList<1>&);
244 
245  //- Remove entries from this list - unset the specified bits
246  inline PackedBoolList& operator-=(const labelUList& indices);
247 
248  //- Remove entries from this list - unset the specified bits
250 };
251 
252 
253 // Global Operators
254 
255 //- Intersect lists - the result is trimmed to the smallest intersecting size
256 PackedBoolList operator&
257 (
258  const PackedBoolList& lst1,
259  const PackedBoolList& lst2
260 );
261 
262 
263 //- Combine to form a unique list (xor)
264 // The result is trimmed to the smallest intersecting size
265 PackedBoolList operator^
266 (
267  const PackedBoolList& lst1,
268  const PackedBoolList& lst2
269 );
270 
271 
272 //- Combine lists
273 PackedBoolList operator|
274 (
275  const PackedBoolList& lst1,
276  const PackedBoolList& lst2
277 );
278 
279 
280 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
281 
282 } // End namespace Foam
283 
284 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
285 
286 #include "PackedBoolListI.H"
287 
288 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
289 
290 #endif
291 
292 // ************************************************************************* //
PackedBoolList & operator &=(const PackedList< 1 > &)
And operator (lists may be dissimilar sizes)
void subset(const PackedList< 1 > &)
Subset with the specified list.
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
List< PackedBoolList > PackedBoolListList
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A dynamically allocatable list of packed unsigned integers.
Definition: PackedList.H:116
void operator=(const bool val)
Assignment of all entries to the given value.
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
PackedBoolList & operator^=(const PackedList< 1 > &)
Xor operator (lists may be dissimilar sizes)
PackedBoolList operator~() const
Complement operator.
PackedBoolList()
Construct null.
PackedBoolList & operator-=(const PackedList< 1 > &)
Remove entries from this list - unset the specified bits.
PackedBoolList & operator+=(const PackedList< 1 > &)
Add entries to this list, synonymous with the or operator.
A bit-packed bool list.
void transfer(PackedBoolList &)
Transfer the contents of the argument list into this list.
A List with indirect addressing.
Definition: fvMatrix.H:106
autoPtr< PackedBoolList > clone() const
Clone.
void unset(const PackedList< 1 > &)
Unset specified bits.
labelList used() const
Return indices of the used (true) elements as a list of labels.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
label size() const
Number of entries.
Definition: PackedListI.H:711
PackedBoolList & operator|=(const PackedList< 1 > &)
Or operator (lists may be dissimilar sizes)
Namespace for OpenFOAM.