PackedListI.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2017-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "error.H"
30 
31 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
32 
33 template<unsigned Width>
34 inline unsigned int Foam::PackedList<Width>::repeated_value(unsigned val)
35 {
36  return BitOps::repeat_value<block_type,Width>(val);
37 }
38 
39 
40 template<unsigned Width>
41 inline unsigned int Foam::PackedList<Width>::readValue(Istream& is)
42 {
43  const unsigned int val = readLabel(is);
44 
45  if (val > max_value)
46  {
48  << "Out-of-range value " << val << " for PackedList<" << Width
49  << ">. Maximum permitted value is " << max_value << "."
50  << exit(FatalIOError);
51  }
52 
53  return val;
54 }
55 
56 
57 template<unsigned Width>
58 inline void Foam::PackedList<Width>::setPair(Istream& is)
59 {
60  is.readBegin("Tuple2<label,uint32>");
61 
62  const label ind = readLabel(is);
63  const unsigned int val = readLabel(is);
64 
65  is.readEnd("Tuple2<label,uint32>");
66 
67  if (val > max_value)
68  {
70  << "Out-of-range value " << val << " for PackedList<" << Width
71  << "> at index " << ind
72  << ". Maximum permitted value is " << max_value << "."
73  << exit(FatalIOError);
74  }
75 
76  set(ind, val);
77 
78  is.check(FUNCTION_NAME);
79 }
80 
81 
82 template<unsigned Width>
84 {
85  // Mask off any partial rubbish in final block
86  const unsigned int blk = size() / elem_per_block;
87  const unsigned int off = size() % elem_per_block;
88 
89  if (off)
90  {
91  blocks_[blk] &= mask_lower(off);
92  }
93 }
94 
95 
96 template<unsigned Width>
97 inline bool Foam::PackedList<Width>::trim(label minpos)
98 {
99  if (empty())
100  {
101  return false; // Trivial case
102  }
103 
104  const label orig = size();
105  if (orig < minpos)
106  {
107  minpos = orig; // Don't allow allow accidental growth!
108  }
109 
110  for (label blocki = num_blocks(size())-1; blocki >= 0; --blocki)
111  {
112  // Truncate to the block begin
113  size_ = blocki * elem_per_block;
114 
115  unsigned int blockval = blocks_[blocki];
116 
117  // Some bits were found in the block, increment size again
118  if (blockval)
119  {
120  for (; blockval; ++size_)
121  {
122  blockval >>= Width;
123  }
124  break;
125  }
126  else if (size_ < minpos)
127  {
128  break;
129  }
130  }
131 
132  if (size_ < minpos)
133  {
134  size_ = minpos;
135  }
136 
137  return (size() != orig);
138 }
139 
140 
141 template<unsigned Width>
142 inline void Foam::PackedList<Width>::copyAssign(const PackedList<Width>& rhs)
143 {
144  // Self-assignment silently ignored
145  blocks_ = rhs.blocks_;
146  size_ = rhs.size_;
147 }
148 
150 // * * * * * * * * * * * * * * * Specializations * * * * * * * * * * * * * * //
151 
152 namespace Foam
153 {
155 // constexpr noexcept
156 template<> inline unsigned int PackedList<1>::repeated_value(unsigned val)
157 {
158  return (val ? ~0u : 0u);
159 }
160 
161 template<> inline unsigned int PackedList<1>::readValue(Istream& is)
162 {
163  return readBool(is);
164 }
165 
166 template<> inline void PackedList<1>::setPair(Istream& is)
167 {
168  set(readLabel(is), true);
169 }
171 } // End namespace Foam
172 
173 
174 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
175 
176 template<unsigned Width>
178 :
179  blocks_(),
180  size_(0)
181 {}
182 
183 
184 template<unsigned Width>
185 inline Foam::PackedList<Width>::PackedList(const label numElem)
186 :
187  blocks_(num_blocks(numElem), 0u),
188  size_(numElem)
189 {}
190 
191 
192 template<unsigned Width>
194 (
195  const label numElem,
196  const unsigned int val
197 )
198 :
199  blocks_(num_blocks(numElem), 0u),
200  size_(numElem)
201 {
202  if (val)
203  {
204  operator=(val);
205  }
206 }
207 
208 
209 template<unsigned Width>
210 inline Foam::PackedList<Width>::PackedList(Istream& is)
211 :
212  blocks_(),
213  size_(0)
214 {
215  readList(is);
216 }
217 
218 
219 template<unsigned Width>
221 :
222  blocks_(list.blocks_),
223  size_(list.size_)
224 {}
225 
226 
227 template<unsigned Width>
229 :
230  blocks_(std::move(list.blocks_)),
231  size_(list.size_)
232 {
233  list.size_ = 0;
234 }
235 
236 
237 template<unsigned Width>
239 :
240  blocks_(num_blocks(values.size()), 0u),
241  size_(values.size())
242 {
243  const label len = values.size();
244 
245  // Could add more intelligent filling (blockwise),
246  // but likely done fairly infrequently
247 
248  for (label i = 0; i < len; ++i)
249  {
250  const unsigned int val(values[i]);
251  if (val) set(i, val);
252  }
253 }
254 
255 
256 template<unsigned Width>
257 template<class Addr>
259 (
260  const IndirectListBase<label, Addr>& values
261 )
262 :
263  blocks_(num_blocks(values.size()), 0u),
264  size_(values.size())
265 {
266  const label len = values.size();
267 
268  // Could add more intelligent filling (blockwise),
269  // but likely done fairly infrequently
270 
271  for (label i = 0; i < len; ++i)
272  {
273  const unsigned int val(values[i]);
274  if (val) set(i, val);
275  }
276 }
277 
278 
279 template<unsigned Width>
282 {
283  return autoPtr<PackedList<Width>>::New(*this);
284 }
285 
286 
287 // * * * * * * * * * * * * * * * * References * * * * * * * * * * * * * * * * //
288 
289 template<unsigned Width>
291 (
292  PackedList<Width>* parent,
293  const label index
294 )
295 :
296  ref_(parent->blocks_[index / elem_per_block]),
297  shift_(Width * (index % elem_per_block))
298 {}
299 
300 
301 template<unsigned Width>
302 inline unsigned int Foam::PackedList<Width>::reference::get() const
303 {
304  return ((ref_ >> shift_) & max_value);
305 }
306 
307 
308 template<unsigned Width>
309 inline bool Foam::PackedList<Width>::reference::set(const unsigned int val)
310 {
311  const unsigned int mask = (max_value << shift_);
312  const unsigned int prev = ref_;
313 
314  if (val >= max_value)
315  {
316  ref_ |= mask; // Overflow is max_value, so fill entirely
317  }
318  else
319  {
320  ref_ &= ~mask;
321  ref_ |= mask & (val << shift_);
322  }
324  return (prev != ref_);
325 }
326 
327 
328 template<unsigned Width>
330 (
331  const reference& other
332 )
333 {
334  // Accepts self-assignment
335  this->set(other.get());
336 }
337 
338 
339 template<unsigned Width>
341 (
342  const unsigned int val
343 )
344 {
345  this->set(val);
346 }
347 
348 
349 template<unsigned Width>
350 inline Foam::PackedList<Width>::reference::operator unsigned int () const
351 {
352  return this->get();
353 }
354 
355 
356 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
357 
358 template<unsigned Width>
359 inline void Foam::PackedList<Width>::checkIndex(const label i) const
360 {
361  if (!size_)
362  {
364  << "attempt to access element " << i << " from zero sized list"
365  << abort(FatalError);
366  }
367  else if (i < 0 || i >= size_)
368  {
370  << "index " << i << " out of range [0," << size_ << ")"
371  << abort(FatalError);
372  }
373 }
374 
375 
376 template<unsigned Width>
377 inline Foam::label Foam::PackedList<Width>::size() const noexcept
378 {
379  return size_;
380 }
381 
382 
383 template<unsigned Width>
385 {
386  return !size_;
387 }
388 
389 
390 template<unsigned Width>
391 inline Foam::label Foam::PackedList<Width>::capacity() const noexcept
392 {
393  return elem_per_block * blocks_.size();
394 }
395 
396 
397 template<unsigned Width>
399 (
400  const label numElem
401 )
402 {
403  this->resize(numElem);
404 }
405 
406 
407 template<unsigned Width>
409 (
410  const label newSize,
411  const unsigned int val
412 )
413 {
414  reserve(newSize);
415 
416  const label oldSize = size();
417  size_ = newSize;
418 
419  if (oldSize < newSize)
420  {
421  // Fill new elements or newly exposed elements
422  if (val)
423  {
424  // Fill value for complete blocks
425  const unsigned int blockval = repeated_value(val);
426 
427  // Fill complete blocks
428  const label oldLen = num_blocks(oldSize);
429  const label newLen = num_blocks(size());
430  for (label blocki = oldLen; blocki < newLen; ++blocki)
431  {
432  blocks_[blocki] = blockval;
433  }
434 
435  // Finish previous partial block, preserve existing value
436  {
437  const unsigned int blk = oldSize / elem_per_block;
438  const unsigned int off = oldSize % elem_per_block;
439  if (off)
440  {
441  const unsigned int mask = mask_lower(off);
442 
443  blocks_[blk] &= mask;
444  blocks_[blk] |= ~mask & blockval;
445  }
446  }
447 
449  }
450  }
451  else if (newSize < oldSize)
452  {
453  // The list is now shorter than before, so we zero assign the unused
454  // blocks and any trailing junk. This costs slightly here, but make
455  // things much simpler elsewhere.
456 
457  // Clear complete blocks
458  const label oldLen = num_blocks(oldSize);
459  const label newLen = num_blocks(size());
460  for (label blocki = newLen; blocki < oldLen; ++blocki)
461  {
462  blocks_[blocki] = 0u;
463  }
466  }
467 }
468 
469 
470 template<unsigned Width>
471 inline void Foam::PackedList<Width>::setCapacity(const label numElem)
472 {
473  const label nblocks = num_blocks(numElem);
474 
475  blocks_.resize(nblocks, 0u);
476 
477  if (numElem < size())
478  {
479  size_ = numElem;
481  }
482 }
483 
484 
485 template<unsigned Width>
486 inline void Foam::PackedList<Width>::reserve(const label numElem)
487 {
488  const label oldLen = blocks_.size();
489  const label newLen = num_blocks(numElem);
490 
491  // Allocate more capacity if necessary
492  if (oldLen < newLen)
493  {
495  (
496  // SizeMin=16, allocation doubling
497  max(16, max(newLen, 2*oldLen)),
498  0u
499  );
500  }
501 }
502 
503 
504 template<unsigned Width>
506 {
507  blocks_ = 0u;
508 }
509 
510 
511 template<unsigned Width>
512 inline void Foam::PackedList<Width>::clear()
513 {
514  reset();
515  size_ = 0;
516 }
517 
518 
519 template<unsigned Width>
521 {
522  blocks_.clear();
523  size_ = 0;
524 }
525 
526 
527 template<unsigned Width>
529 {
530  // Any unneeded space allocated?
531  const label nblocks = num_blocks(size());
532  if (nblocks < blocks_.size())
533  {
534  blocks_.resize(nblocks);
535  }
536 }
537 
538 
539 template<unsigned Width>
541 {
542  return blocks_;
543 }
544 
545 
546 template<unsigned Width>
548 {
549  return blocks_;
550 }
551 
552 
553 template<unsigned Width>
554 inline Foam::label Foam::PackedList<Width>::nBlocks() const
555 {
556  return num_blocks(size());
557 }
558 
559 
560 template<unsigned Width>
561 inline const unsigned int* Foam::PackedList<Width>::cdata() const noexcept
562 {
563  return blocks_.cdata();
564 }
565 
566 
567 template<unsigned Width>
569 {
570  return blocks_.data();
571 }
572 
573 
574 template<unsigned Width>
576 {
577  return blocks_.cdata_bytes();
578 }
579 
580 
581 template<unsigned Width>
583 {
584  return blocks_.data_bytes();
585 }
586 
587 
588 template<unsigned Width>
589 inline std::streamsize Foam::PackedList<Width>::size_bytes() const noexcept
590 {
591  return num_blocks(size()) * sizeof(block_type);
592 }
593 
594 
595 template<unsigned Width>
596 inline std::streamsize Foam::PackedList<Width>::byteSize() const noexcept
597 {
598  return this->size_bytes();
599 }
600 
601 
602 template<unsigned Width>
604 {
605  if (this == &rhs)
606  {
607  return; // Self-swap is a no-op
608  }
610  blocks_.swap(rhs.blocks_);
611  std::swap(size_, rhs.size_);
612 }
613 
614 
615 template<unsigned Width>
617 {
618  if (this == &rhs)
619  {
620  return; // Self-assignment is a no-op
621  }
622 
624  size_ = rhs.size_;
625  rhs.size_ = 0;
626 }
627 
628 
629 template<unsigned Width>
630 inline unsigned int Foam::PackedList<Width>::get(const label i) const
631 {
632  if (i < 0 || i >= size())
633  {
634  #ifdef FULLDEBUG
635  if (i < 0)
636  {
638  << "Ignoring attempt to get a negative index " << i
639  << " range is [0," << size_ << ")"
640  << endl;
641  }
642  #endif
643 
644  return 0u; // Out-of-bounds (lazy): return 0 (false)
645  }
647  return reference(const_cast<PackedList<Width>*>(this), i).get();
648 }
649 
650 
651 template<unsigned Width>
653 (
654  const label i,
655  const unsigned int val
656 )
657 {
658  if (i < 0)
659  {
660  #ifdef FULLDEBUG
662  << "Ignoring attempt to set a negative index " << i
663  << " range is [0," << size_ << ")"
664  << endl;
665  #endif
666 
667  return false; // Out-of-bounds: ignore
668  }
669  else if (i >= size())
670  {
671  if (!val) // Unset out-of-bounds: ignore
672  {
673  return false;
674  }
675 
676  resize(i + 1); // Lazy evaluation: adjust size for assign
677  }
678 
679  return reference(this, i).set(val);
680 }
681 
682 
683 template<unsigned Width>
684 inline bool Foam::PackedList<Width>::unset(const label i)
685 {
686  if (i < 0 || i >= size())
687  {
688  return false; // Unset out-of-bounds: ignore
689  }
690 
691  return reference(this, i).set(0u);
692 }
693 
694 
695 template<unsigned Width>
696 inline void Foam::PackedList<Width>::push_back(const unsigned int val)
697 {
698  const label idx = size();
699  reserve(idx + 1);
700  ++size_;
701 
702  reference(this, idx).set(val);
703 }
704 
705 
706 template<unsigned Width>
707 inline void Foam::PackedList<Width>::pop_back(label n)
708 {
709  if (n >= size())
710  {
711  clear();
712  }
713  else if (n > 0)
714  {
715  resize(size() - n);
716  }
717 }
718 
719 
720 template<unsigned Width>
721 inline unsigned int Foam::PackedList<Width>::remove()
722 {
723  // Location of last element and simultaneously the new size
724  const label idx = size()-1;
725 
726  if (idx < 0)
727  {
729  << "List is empty" << abort(FatalError);
730  }
731 
732  const unsigned int old = reference(this, idx).get();
733  resize(idx);
734 
735  return old;
736 }
737 
738 
739 template<unsigned Width>
740 inline void Foam::PackedList<Width>::fill(const unsigned int val)
741 {
742  if (empty())
743  {
744  return; // Trivial case
745  }
746 
747  const label nblocks = num_blocks(size());
748 
749  // Fill value for complete blocks
750  const unsigned int blockval = (val ? repeated_value(val) : 0u);
751 
752  for (label blocki=0; blocki < nblocks; ++blocki)
753  {
754  blocks_[blocki] = blockval;
755  }
756 
757  if (val)
758  {
760  }
761 }
762 
763 
764 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
765 
766 template<unsigned Width>
767 inline unsigned int Foam::PackedList<Width>::operator[](const label i) const
768 {
769  return get(i);
770 }
771 
772 
773 template<unsigned Width>
776 {
777  #ifdef FULLDEBUG
779  #endif
780  return reference(this, i);
781 }
782 
783 
784 template<unsigned Width>
786 {
787  copyAssign(rhs);
788 }
789 
790 
791 template<unsigned Width>
793 {
794  transfer(rhs);
795 }
796 
797 
798 template<unsigned Width>
799 inline void Foam::PackedList<Width>::operator=(const unsigned int val)
800 {
801  fill(val);
802 }
803 
804 
805 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
806 
807 template<unsigned Width>
808 inline bool Foam::operator==
809 (
810  const PackedList<Width>& a,
811  const PackedList<Width>& b
812 )
813 {
814  return a.equal(b);
815 }
816 
817 
818 template<unsigned Width>
819 inline bool Foam::operator!=
820 (
821  const PackedList<Width>& a,
822  const PackedList<Width>& b
823 )
824 {
825  return !a.equal(b);
826 }
827 
828 
829 // ************************************************************************* //
void setCapacity(const label numElem)
Alter the size of the underlying storage.
Definition: PackedListI.H:464
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:118
label size() const noexcept
Number of entries.
Definition: PackedListI.H:370
unsigned int get() const
Get value as unsigned, no range-checking.
Definition: PackedListI.H:295
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
bool unset(const label i)
Unset the entry at index i.
Definition: PackedListI.H:677
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:132
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument list.
Definition: List.C:439
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:578
std::streamsize byteSize() const noexcept
The number of bytes used in the raw storage including any unused padding.
Definition: PackedListI.H:589
const char * cdata_bytes() const noexcept
A const pointer to the raw storage, reinterpreted as byte data.
Definition: PackedListI.H:568
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
std::streamsize size_bytes() const noexcept
The number of bytes used in the raw storage including any unused padding.
Definition: PackedListI.H:582
autoPtr< PackedList< Width > > clone() const
Clone.
Definition: PackedListI.H:274
const List< unsigned int > & storage() const
Return the underlying storage blocks.
Definition: PackedListI.H:540
T * data() noexcept
Return pointer to the underlying array serving as data storage.
Definition: UListI.H:230
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
unsigned int remove()
Remove and return the last element.
Definition: PackedListI.H:714
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
Definition: label.H:63
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
unsigned int operator[](const label i) const
Identical to get() - get value at index.
Definition: PackedListI.H:760
void setPair(Istream &is)
Read an index/value pair and set accordingly.
Definition: PackedListI.H:51
void operator=(const PackedList< Width > &lst)
Copy assignment.
Definition: PackedListI.H:778
char * data_bytes() noexcept
Return pointer to the underlying array serving as data storage,.
Definition: UListI.H:244
void swap(UList< T > &list)
Swap content with another UList of the same type in constant time.
Definition: UListI.H:427
A reference supporting read/write access to an entry.
Definition: PackedList.H:640
label nBlocks() const
The number of internal storage blocks.
Definition: PackedListI.H:547
void resize(const label numElem, const unsigned int val=0u)
Reset addressable list size, does not shrink the allocated size.
Definition: PackedListI.H:402
const char * cdata_bytes() const noexcept
Return pointer to the underlying array serving as data storage,.
Definition: UListI.H:237
static unsigned int repeated_value(unsigned val)
Enforce non-zero Width to fit within the block storage and require at least 2 items per storage block...
Definition: PackedListI.H:27
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Definition: HashOps.H:164
constexpr PackedList() noexcept
Default construct, zero-sized and no allocation.
Definition: PackedListI.H:170
A dynamic list of packed unsigned integers, with the number of bits per item specified by the <Width>...
Definition: PackedList.H:104
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:109
void fill(const unsigned int val)
Assign all entries to the given value.
Definition: PackedListI.H:733
static unsigned int readValue(Istream &is)
Read a list entry (allows for specialization)
Definition: PackedListI.H:34
label size_
Number of entries used.
Definition: PackedList.H:208
bool set(unsigned int val)
Set value, returning true if changed, no range-checking.
Definition: PackedListI.H:302
bool set(const label i, unsigned int val=~0u)
Set value at index i, default value set is the max_value.
Definition: PackedListI.H:646
errorManip< error > abort(error &err)
Definition: errorManip.H:139
void clear()
Clear the list, i.e. set addressable size to zero.
Definition: PackedListI.H:505
const direction noexcept
Definition: Scalar.H:258
void reserve(const label numElem)
Reserve allocation space for at least this size (uses a size doubling strategy).
Definition: PackedListI.H:479
unsigned shift_
The bit shift to access the given sub-portion.
Definition: PackedList.H:655
#define FUNCTION_NAME
block_type & ref_
Reference to the block.
Definition: PackedList.H:650
void swap(PackedList< Width > &rhs)
Swap contents with argument.
Definition: PackedListI.H:596
static constexpr block_type max_value
The max value for an element which is also the bit-mask of the individual element.
Definition: PackedList.H:161
unsigned int block_type
The storage block type for bit elements.
Definition: PackedList.H:135
bool empty() const noexcept
True if the list is empty (ie, size() is zero).
Definition: PackedListI.H:377
char * data_bytes() noexcept
A pointer to the raw storage, reinterpreted as byte data.
Definition: PackedListI.H:575
#define WarningInFunction
Report a warning using Foam::Warning.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:607
void resize_nocopy(const label numElem)
Currently identical to resize. Subject to future change (Oct-2021)
Definition: PackedListI.H:392
unsigned int * data() noexcept
A pointer to the raw storage.
Definition: PackedListI.H:561
block_container blocks_
The blocks of raw data.
Definition: PackedList.H:203
label n
static constexpr block_type mask_lower(unsigned elementOffset)
Masking for all bits below the element offset.
Definition: PackedList.H:185
void push_back(const unsigned int val)
Append a value at the end of the list.
Definition: PackedListI.H:689
void clearStorage()
Clear the list and delete storage.
Definition: PackedListI.H:513
void copyAssign(const PackedList< Width > &rhs)
Copy assignment.
Definition: PackedListI.H:135
static constexpr label num_blocks(label numElem) noexcept
Calculate the number of blocks required to _address_ the requested number of elements.
Definition: PackedList.H:175
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
const T * cdata() const noexcept
Return pointer to the underlying array serving as data storage.
Definition: UListI.H:223
void reset()
Clear all bits but do not adjust the addressable size.
Definition: PackedListI.H:498
static constexpr unsigned elem_per_block
The number of elements stored per data block.
Definition: PackedList.H:153
void clear_trailing_bits()
Clear any partial rubbish in the last addressable block.
Definition: PackedListI.H:76
const unsigned int * cdata() const noexcept
A const pointer to the raw storage.
Definition: PackedListI.H:554
void transfer(PackedList< Width > &rhs)
Transfer the contents of the argument list into this list and annul the argument list.
Definition: PackedListI.H:609
bool trim(label minpos=-1)
Trim any trailing zero elements, optionally specifying a a minimum position, below which trimming wil...
Definition: PackedListI.H:90
label capacity() const noexcept
The number of elements that can be stored with reallocating.
Definition: PackedListI.H:384
unsigned int get(const label i) const
Get value at index i or 0 for out-of-range.
Definition: PackedListI.H:623
void shrink()
Shrink the allocated space to what is actually used.
Definition: PackedListI.H:521
reference(PackedList *parent, const label index)
Construct by taking reference of block from within the list and the specified index.
bool readBool(Istream &is)
Read bool from stream using Foam::Switch(Istream&)
Definition: bool.C:62
Namespace for OpenFOAM.
void checkIndex(const label i) const
Check index is within valid range [0,size)
Definition: PackedListI.H:352
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...
void pop_back(label n=1)
Reduce size by 1 or more elements. Can be called on an empty list.
Definition: PackedListI.H:700