PackedBoolList.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 | Copyright (C) 2011-2016 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, initializes 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 by transferring the parameter contents
112  inline PackedBoolList(const Xfer<PackedBoolList>&);
113 
114  //- Construct by transferring the parameter contents
115  inline PackedBoolList(const Xfer<PackedList<1>>&);
116 
117  //- Construct from a list of bools
118  explicit inline PackedBoolList(const Foam::UList<bool>&);
119 
120  //- Construct from a list of labels
121  // using the labels as indices to indicate which bits are set
122  explicit inline PackedBoolList(const labelUList& indices);
123 
124  //- Construct from a list of labels
125  // using the labels as indices to indicate which bits are set
126  explicit inline PackedBoolList(const UIndirectList<label>& indices);
127 
128  //- Clone
129  inline autoPtr<PackedBoolList> clone() const;
130 
131 
132  // Member Functions
133 
134  // Access
135 
136  using PackedList<1>::set;
137  using PackedList<1>::unset;
138 
139  //- Set specified bits.
140  void set(const PackedList<1>&);
141 
142  //- Set the listed indices. Return number of elements changed.
143  // Does auto-vivify for non-existent entries.
144  label set(const labelUList& indices);
145 
146  //- Set the listed indices. Return number of elements changed.
147  // Does auto-vivify for non-existent entries.
148  label set(const UIndirectList<label>& indices);
149 
150  //- Unset specified bits.
151  void unset(const PackedList<1>&);
152 
153  //- Unset the listed indices. Return number of elements changed.
154  // Never auto-vivify entries.
155  label unset(const labelUList& indices);
156 
157  //- Unset the listed indices. Return number of elements changed.
158  // Never auto-vivify entries.
159  label unset(const UIndirectList<label>& indices);
160 
161  //- Subset with the specified list.
162  void subset(const PackedList<1>&);
163 
164  //- Subset with the listed indices.
165  // Return number of elements subsetted.
166  label subset(const labelUList& indices);
167 
168  //- Subset with the listed indices.
169  // Return number of elements subsetted.
170  label subset(const UIndirectList<label>& indices);
171 
172 
173  //- Return indices of the used (true) elements as a list of labels
174  Xfer<labelList> used() const;
175 
176 
177  // Edit
178 
179  //- Transfer the contents of the argument list into this list
180  // and annul the argument list.
181  inline void transfer(PackedBoolList&);
182 
183  //- Transfer the contents of the argument list into this list
184  // and annul the argument list.
185  inline void transfer(PackedList<1>&);
186 
187  //- Transfer contents to the Xfer container
188  inline Xfer<PackedBoolList> xfer();
189 
190 
191  // Member Operators
192 
193  //- Assignment of all entries to the given value.
194  inline void operator=(const bool val);
195 
196  //- Assignment operator.
197  inline void operator=(const PackedBoolList&);
198 
199  //- Assignment operator.
200  inline void operator=(const PackedList<1>&);
201 
202  //- Assignment operator.
203  void operator=(const Foam::UList<bool>&);
204 
205  //- Assignment operator,
206  // using the labels as indices to indicate which bits are set
207  inline void operator=(const labelUList& indices);
208 
209  //- Assignment operator,
210  // using the labels as indices to indicate which bits are set
211  inline void operator=(const UIndirectList<label>&);
212 
213  //- Complement operator
214  inline PackedBoolList operator~() const;
215 
216  //- And operator (lists may be dissimilar sizes)
217  inline PackedBoolList& operator&=(const PackedList<1>&);
218 
219  //- And operator (lists may be dissimilar sizes)
220  // using the labels as indices to indicate which bits are set
221  inline PackedBoolList& operator&=(const labelUList& indices);
222 
223  //- And operator (lists may be dissimilar sizes)
224  // using the labels as indices to indicate which bits are set
226 
227  //- Xor operator (lists may be dissimilar sizes)
228  // Retains unique entries
230 
231  //- Or operator (lists may be dissimilar sizes)
232  inline PackedBoolList& operator|=(const PackedList<1>&);
233 
234  //- Or operator (lists may be dissimilar sizes),
235  // using the labels as indices to indicate which bits are set
236  inline PackedBoolList& operator|=(const labelUList& indices);
237 
238  //- Or operator (lists may be dissimilar sizes),
239  // using the labels as indices to indicate which bits are set
241 
242 
243  //- Add entries to this list, synonymous with the or operator
244  inline PackedBoolList& operator+=(const PackedList<1>&);
245 
246  //- Add entries to this list, synonymous with the or operator
247  inline PackedBoolList& operator+=(const labelUList& indices);
248 
249  //- Add entries to this list, synonymous with the or operator
251 
252  //- Remove entries from this list - unset the specified bits
253  inline PackedBoolList& operator-=(const PackedList<1>&);
254 
255  //- Remove entries from this list - unset the specified bits
256  inline PackedBoolList& operator-=(const labelUList& indices);
257 
258  //- Remove entries from this list - unset the specified bits
260 };
261 
262 
263 // Global Operators
264 
265 //- Intersect lists - the result is trimmed to the smallest intersecting size
266 PackedBoolList operator&
267 (
268  const PackedBoolList& lst1,
269  const PackedBoolList& lst2
270 );
271 
272 
273 //- Combine to form a unique list (xor)
274 // The result is trimmed to the smallest intersecting size
275 PackedBoolList operator^
276 (
277  const PackedBoolList& lst1,
278  const PackedBoolList& lst2
279 );
280 
281 
282 //- Combine lists
283 PackedBoolList operator|
284 (
285  const PackedBoolList& lst1,
286  const PackedBoolList& lst2
287 );
288 
289 
290 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
291 
292 } // End namespace Foam
293 
294 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
295 
296 #include "PackedBoolListI.H"
297 
298 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
299 
300 #endif
301 
302 // ************************************************************************* //
PackedBoolList & operator &=(const PackedList< 1 > &)
And operator (lists may be dissimilar sizes)
void subset(const PackedList< 1 > &)
Subset with the specified list.
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
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
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:60
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:117
Xfer< PackedBoolList > xfer()
Transfer contents to the Xfer container.
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:61
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.
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:713
PackedBoolList & operator|=(const PackedList< 1 > &)
Or operator (lists may be dissimilar sizes)
Xfer< labelList > used() const
Return indices of the used (true) elements as a list of labels.
Namespace for OpenFOAM.