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-2023 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 
149 
150 template<unsigned Width>
151 inline Foam::label Foam::PackedList<Width>::first_block() const
152 {
153  if (size())
154  {
155  const label nblocks = num_blocks(size());
156 
157  for (label blocki=0; blocki < nblocks; ++blocki)
158  {
159  if (blocks_[blocki])
160  {
161  return blocki;
162  }
163  }
164  }
165 
166  return -1;
167 }
168 
169 
170 template<unsigned Width>
171 inline Foam::label Foam::PackedList<Width>::first_not_block() const
172 {
173  if (!size())
174  {
175  return -1;
176  }
177 
178  // Check on complement (changes 0 <-> 1).
179  // If any 1's now appear, there was a 0 bit before
180 
181  const label nblocks = num_blocks(size());
182 
183  // Extra bits in the final block?
184  const unsigned int off = size() % elem_per_block;
185 
186  if (!off)
187  {
188  for (label blocki=0; blocki < nblocks; ++blocki)
189  {
190  if (~(blocks_[blocki]))
191  {
192  return blocki;
193  }
194  }
195  }
196  else
197  {
198  for (label blocki=0; blocki < nblocks-1; ++blocki)
199  {
200  if (~(blocks_[blocki]))
201  {
202  return blocki;
203  }
204  }
205 
206  // The final block needs masking
207  if (~(blocks_[nblocks-1]) & mask_lower(off))
208  {
209  return nblocks-1;
210  }
211  }
212 
213  return -1;
214 }
215 
217 // * * * * * * * * * * * * * * * Specializations * * * * * * * * * * * * * * //
218 
219 namespace Foam
220 {
222 // constexpr noexcept
223 template<> inline unsigned int PackedList<1>::repeated_value(unsigned val)
224 {
225  return (val ? ~0u : 0u);
226 }
227 
228 template<> inline unsigned int PackedList<1>::readValue(Istream& is)
229 {
230  return readBool(is);
231 }
232 
233 template<> inline void PackedList<1>::setPair(Istream& is)
234 {
235  set(readLabel(is), true);
236 }
238 } // End namespace Foam
239 
240 
241 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
242 
243 template<unsigned Width>
245 :
246  blocks_(),
247  size_(0)
248 {}
249 
250 
251 template<unsigned Width>
252 inline Foam::PackedList<Width>::PackedList(const label numElem)
253 :
254  blocks_(num_blocks(numElem), 0u),
255  size_(numElem)
256 {}
257 
258 
259 template<unsigned Width>
261 (
262  const label numElem,
263  const unsigned int val
264 )
265 :
266  blocks_(num_blocks(numElem), 0u),
267  size_(numElem)
268 {
269  if (val)
270  {
271  operator=(val);
272  }
273 }
274 
275 
276 template<unsigned Width>
277 inline Foam::PackedList<Width>::PackedList(Istream& is)
278 :
279  blocks_(),
280  size_(0)
281 {
282  readList(is);
283 }
284 
285 
286 template<unsigned Width>
288 :
289  blocks_(list.blocks_),
290  size_(list.size_)
291 {}
292 
293 
294 template<unsigned Width>
296 :
297  blocks_(std::move(list.blocks_)),
298  size_(list.size_)
299 {
300  list.size_ = 0;
301 }
302 
303 
304 template<unsigned Width>
306 :
307  blocks_(num_blocks(values.size()), 0u),
308  size_(values.size())
309 {
310  const label len = values.size();
311 
312  // Could add more intelligent filling (blockwise),
313  // but likely done fairly infrequently
314 
315  for (label i = 0; i < len; ++i)
316  {
317  const unsigned int val(values[i]);
318  if (val) set(i, val);
319  }
320 }
321 
322 
323 template<unsigned Width>
324 template<class Addr>
326 (
327  const IndirectListBase<label, Addr>& values
328 )
329 :
330  blocks_(num_blocks(values.size()), 0u),
331  size_(values.size())
332 {
333  const label len = values.size();
334 
335  // Could add more intelligent filling (blockwise),
336  // but likely done fairly infrequently
337 
338  for (label i = 0; i < len; ++i)
339  {
340  const unsigned int val(values[i]);
341  if (val) set(i, val);
342  }
343 }
344 
345 
346 template<unsigned Width>
349 {
350  return autoPtr<PackedList<Width>>::New(*this);
351 }
352 
353 
354 // * * * * * * * * * * * * * * * * References * * * * * * * * * * * * * * * * //
355 
356 template<unsigned Width>
358 (
359  PackedList<Width>* parent,
360  const label index
361 )
362 :
363  ref_(parent->blocks_[index / elem_per_block]),
364  shift_(Width * (index % elem_per_block))
365 {}
366 
367 
368 template<unsigned Width>
369 inline unsigned int Foam::PackedList<Width>::reference::get() const
370 {
371  return ((ref_ >> shift_) & max_value);
372 }
373 
374 
375 template<unsigned Width>
376 inline bool Foam::PackedList<Width>::reference::set(const unsigned int val)
377 {
378  const unsigned int mask = (max_value << shift_);
379  const unsigned int prev = ref_;
380 
381  if (val >= max_value)
382  {
383  ref_ |= mask; // Overflow is max_value, so fill entirely
384  }
385  else
386  {
387  ref_ &= ~mask;
388  ref_ |= mask & (val << shift_);
389  }
391  return (prev != ref_);
392 }
393 
394 
395 template<unsigned Width>
397 (
398  const reference& other
399 )
400 {
401  // Accepts self-assignment
402  this->set(other.get());
403 }
404 
405 
406 template<unsigned Width>
408 (
409  const unsigned int val
410 )
411 {
412  this->set(val);
413 }
414 
415 
416 template<unsigned Width>
417 inline Foam::PackedList<Width>::reference::operator unsigned int () const
418 {
419  return this->get();
420 }
421 
422 
423 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
424 
425 template<unsigned Width>
426 inline void Foam::PackedList<Width>::checkIndex(const label i) const
427 {
428  if (!size_)
429  {
431  << "attempt to access element " << i << " from zero sized list"
432  << abort(FatalError);
433  }
434  else if (i < 0 || i >= size_)
435  {
437  << "index " << i << " out of range [0," << size_ << ")"
438  << abort(FatalError);
439  }
440 }
441 
442 
443 template<unsigned Width>
444 inline Foam::label Foam::PackedList<Width>::capacity() const noexcept
445 {
446  return elem_per_block * blocks_.size();
447 }
448 
449 
450 template<unsigned Width>
452 (
453  const label numElem
454 )
455 {
456  this->resize(numElem);
457 }
458 
459 
460 template<unsigned Width>
462 (
463  const label newSize,
464  const unsigned int val
465 )
466 {
467  reserve(newSize);
468 
469  const label oldSize = size();
470  size_ = newSize;
471 
472  if (oldSize < newSize)
473  {
474  // Fill new elements or newly exposed elements
475  if (val)
476  {
477  // Fill value for complete blocks
478  const unsigned int blockval = repeated_value(val);
479 
480  // Fill complete blocks
481  const label oldLen = num_blocks(oldSize);
482  const label newLen = num_blocks(size());
483  for (label blocki = oldLen; blocki < newLen; ++blocki)
484  {
485  blocks_[blocki] = blockval;
486  }
487 
488  // Finish previous partial block, preserve existing value
489  {
490  const unsigned int blk = oldSize / elem_per_block;
491  const unsigned int off = oldSize % elem_per_block;
492  if (off)
493  {
494  const unsigned int mask = mask_lower(off);
495 
496  blocks_[blk] &= mask;
497  blocks_[blk] |= ~mask & blockval;
498  }
499  }
500 
502  }
503  }
504  else if (newSize < oldSize)
505  {
506  // The list is now shorter than before, so we zero assign the unused
507  // blocks and any trailing junk. This costs slightly here, but make
508  // things much simpler elsewhere.
509 
510  // Clear complete blocks
511  const label oldLen = num_blocks(oldSize);
512  const label newLen = num_blocks(size());
513  for (label blocki = newLen; blocki < oldLen; ++blocki)
514  {
515  blocks_[blocki] = 0u;
516  }
519  }
520 }
521 
522 
523 template<unsigned Width>
524 inline void Foam::PackedList<Width>::setCapacity(const label numElem)
525 {
526  const label nblocks = num_blocks(numElem);
527 
528  blocks_.resize(nblocks, 0u);
529 
530  if (numElem < size())
531  {
532  size_ = numElem;
534  }
535 }
536 
537 
538 template<unsigned Width>
539 inline void Foam::PackedList<Width>::reserve(const label numElem)
540 {
541  const label oldLen = blocks_.size();
542  const label newLen = num_blocks(numElem);
543 
544  // Allocate more capacity if necessary
545  if (oldLen < newLen)
546  {
548  (
549  // SizeMin=16, allocation doubling
550  max(16, max(newLen, 2*oldLen)),
551  0u
552  );
553  }
554 }
555 
556 
557 template<unsigned Width>
559 {
560  blocks_ = 0u;
561 }
562 
563 
564 template<unsigned Width>
565 inline void Foam::PackedList<Width>::clear()
566 {
567  reset();
568  size_ = 0;
569 }
570 
571 
572 template<unsigned Width>
574 {
575  blocks_.clear();
576  size_ = 0;
577 }
578 
579 
580 template<unsigned Width>
582 {
583  // Any unneeded space allocated?
584  const label nblocks = num_blocks(size());
585  if (nblocks < blocks_.size())
586  {
587  blocks_.resize(nblocks);
588  }
589 }
590 
591 
592 template<unsigned Width>
594 {
595  return blocks_;
596 }
597 
598 
599 template<unsigned Width>
601 {
602  return blocks_;
603 }
604 
605 
606 template<unsigned Width>
607 inline Foam::label Foam::PackedList<Width>::nBlocks() const
608 {
609  return num_blocks(size());
610 }
611 
612 
613 template<unsigned Width>
614 inline const unsigned int* Foam::PackedList<Width>::cdata() const noexcept
615 {
616  return blocks_.cdata();
617 }
618 
619 
620 template<unsigned Width>
622 {
623  return blocks_.data();
624 }
625 
626 
627 template<unsigned Width>
629 {
630  return blocks_.cdata_bytes();
631 }
632 
633 
634 template<unsigned Width>
636 {
637  return blocks_.data_bytes();
638 }
639 
640 
641 template<unsigned Width>
642 inline std::streamsize Foam::PackedList<Width>::size_data() const noexcept
643 {
644  return num_blocks(size());
645 }
646 
647 
648 template<unsigned Width>
649 inline std::streamsize Foam::PackedList<Width>::size_bytes() const noexcept
650 {
651  return num_blocks(size()) * sizeof(block_type);
652 }
653 
654 
655 template<unsigned Width>
656 inline std::streamsize Foam::PackedList<Width>::byteSize() const noexcept
657 {
658  return this->size_bytes();
659 }
660 
661 
662 template<unsigned Width>
664 {
665  if (this == &rhs)
666  {
667  return; // Self-swap is a no-op
668  }
670  blocks_.swap(rhs.blocks_);
671  std::swap(size_, rhs.size_);
672 }
673 
674 
675 template<unsigned Width>
677 {
678  if (this == &rhs)
679  {
680  return; // Self-assignment is a no-op
681  }
682 
684  size_ = rhs.size_;
685  rhs.size_ = 0;
686 }
687 
688 
689 template<unsigned Width>
690 inline unsigned int Foam::PackedList<Width>::get(const label i) const
691 {
692  if (i < 0 || i >= size())
693  {
694  #ifdef FULLDEBUG
695  if (i < 0)
696  {
698  << "Ignoring attempt to get a negative index " << i
699  << " range is [0," << size_ << ")"
700  << endl;
701  }
702  #endif
703 
704  return 0u; // Out-of-bounds (lazy): return 0 (false)
705  }
707  return reference(const_cast<PackedList<Width>*>(this), i).get();
708 }
709 
710 
711 template<unsigned Width>
713 (
714  const label i,
715  const unsigned int val
716 )
717 {
718  if (i < 0)
719  {
720  #ifdef FULLDEBUG
722  << "Ignoring attempt to set a negative index " << i
723  << " range is [0," << size_ << ")"
724  << endl;
725  #endif
726 
727  return false; // Out-of-bounds: ignore
728  }
729  else if (i >= size())
730  {
731  if (!val) // Unset out-of-bounds: ignore
732  {
733  return false;
734  }
735 
736  resize(i + 1); // Lazy evaluation: adjust size for assign
737  }
738 
739  return reference(this, i).set(val);
740 }
741 
742 
743 template<unsigned Width>
744 inline bool Foam::PackedList<Width>::unset(const label i)
745 {
746  if (i < 0 || i >= size())
747  {
748  return false; // Unset out-of-bounds: ignore
749  }
750 
751  return reference(this, i).set(0u);
752 }
753 
754 
755 template<unsigned Width>
756 inline void Foam::PackedList<Width>::push_back(const unsigned int val)
757 {
758  const label idx = size();
759  reserve(idx + 1);
760  ++size_;
761 
762  reference(this, idx).set(val);
763 }
764 
765 
766 template<unsigned Width>
767 inline void Foam::PackedList<Width>::pop_back(label n)
768 {
769  if (n >= size())
770  {
771  clear();
772  }
773  else if (n > 0)
774  {
775  resize(size() - n);
776  }
777 }
778 
779 
780 template<unsigned Width>
781 inline unsigned int Foam::PackedList<Width>::remove()
782 {
783  // Location of last element and simultaneously the new size
784  const label idx = size()-1;
785 
786  if (idx < 0)
787  {
789  << "List is empty" << abort(FatalError);
790  }
791 
792  const unsigned int old = reference(this, idx).get();
793  resize(idx);
794 
795  return old;
796 }
797 
798 
799 template<unsigned Width>
800 inline void Foam::PackedList<Width>::fill(const unsigned int val)
801 {
802  if (empty())
803  {
804  return; // Trivial case
805  }
806 
807  const label nblocks = num_blocks(size());
808 
809  // Fill value for complete blocks
810  const unsigned int blockval = (val ? repeated_value(val) : 0u);
811 
812  for (label blocki=0; blocki < nblocks; ++blocki)
813  {
814  blocks_[blocki] = blockval;
815  }
816 
817  if (val)
818  {
820  }
821 }
822 
823 
824 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
825 
826 template<unsigned Width>
827 inline unsigned int Foam::PackedList<Width>::operator[](const label i) const
828 {
829  return get(i);
830 }
831 
832 
833 template<unsigned Width>
836 {
837  #ifdef FULLDEBUG
839  #endif
840  return reference(this, i);
841 }
842 
843 
844 template<unsigned Width>
846 {
847  copyAssign(rhs);
848 }
849 
850 
851 template<unsigned Width>
853 {
854  transfer(rhs);
855 }
856 
857 
858 template<unsigned Width>
859 inline void Foam::PackedList<Width>::operator=(const unsigned int val)
860 {
861  fill(val);
862 }
863 
864 
865 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
866 
867 template<unsigned Width>
868 inline bool Foam::operator==
869 (
870  const PackedList<Width>& a,
871  const PackedList<Width>& b
872 )
873 {
874  return a.equal(b);
875 }
876 
877 
878 template<unsigned Width>
879 inline bool Foam::operator!=
880 (
881  const PackedList<Width>& a,
882  const PackedList<Width>& b
883 )
884 {
885  return !a.equal(b);
886 }
887 
888 
889 // ************************************************************************* //
void setCapacity(const label numElem)
Alter the size of the underlying storage.
Definition: PackedListI.H:517
void swap(UList< T > &list) noexcept
Swap content with another UList of the same type in constant time.
Definition: UListI.H:505
std::streamsize size_data() const noexcept
The number of integer blocks addressed in the raw storage.
Definition: PackedListI.H:635
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
unsigned int get() const
Get value as unsigned, no range-checking.
Definition: PackedListI.H:362
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:737
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:160
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument list.
Definition: List.C:326
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:598
std::streamsize byteSize() const noexcept
The number of bytes used in the raw storage including any unused padding.
Definition: PackedListI.H:649
const char * cdata_bytes() const noexcept
A const pointer to the raw storage, reinterpreted as byte data.
Definition: PackedListI.H:621
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:642
autoPtr< PackedList< Width > > clone() const
Clone.
Definition: PackedListI.H:341
const List< unsigned int > & storage() const
Return the underlying storage blocks.
Definition: PackedListI.H:593
T * data() noexcept
Return pointer to the underlying array serving as data storage.
Definition: UListI.H:272
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
unsigned int remove()
Remove and return the last element.
Definition: PackedListI.H:774
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
Definition: label.H:63
unsigned int operator[](const label i) const
Identical to get() - get value at index.
Definition: PackedListI.H:820
void setPair(Istream &is)
Read an index/value pair and set accordingly.
Definition: PackedListI.H:51
char * data_bytes() noexcept
Return pointer to the underlying array serving as data storage,.
Definition: UListI.H:286
A reference supporting read/write access to an entry.
Definition: PackedList.H:659
label nBlocks() const
The number of internal storage blocks.
Definition: PackedListI.H:600
void resize(const label numElem, const unsigned int val=0u)
Reset addressable list size, does not shrink the allocated size.
Definition: PackedListI.H:455
label first_block() const
Find the first block with a &#39;1&#39; bit.
Definition: PackedListI.H:144
const char * cdata_bytes() const noexcept
Return pointer to the underlying array serving as data storage,.
Definition: UListI.H:279
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:237
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:137
void fill(const unsigned int val)
Assign all entries to the given value.
Definition: PackedListI.H:793
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:369
bool set(const label i, unsigned int val=~0u)
Set value at index i, default value set is the max_value.
Definition: PackedListI.H:706
errorManip< error > abort(error &err)
Definition: errorManip.H:139
void clear()
Clear the list, i.e. set addressable size to zero.
Definition: PackedListI.H:558
label first_not_block() const
Find the first block with a &#39;0&#39; bit.
Definition: PackedListI.H:164
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:532
unsigned shift_
The bit shift to access the given sub-portion.
Definition: PackedList.H:674
#define FUNCTION_NAME
block_type & ref_
Reference to the block.
Definition: PackedList.H:669
void swap(PackedList< Width > &rhs)
Swap contents with argument.
Definition: PackedListI.H:656
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: PackedList.H:366
char * data_bytes() noexcept
A pointer to the raw storage, reinterpreted as byte data.
Definition: PackedListI.H:628
#define WarningInFunction
Report a warning using Foam::Warning.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:627
void resize_nocopy(const label numElem)
Currently identical to resize. Subject to future change (Oct-2021)
Definition: PackedListI.H:445
unsigned int * data() noexcept
A pointer to the raw storage.
Definition: PackedListI.H:614
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:749
void clearStorage()
Clear the list and delete storage.
Definition: PackedListI.H:566
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:265
void reset()
Clear all bits but do not adjust the addressable size.
Definition: PackedListI.H:551
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:607
void transfer(PackedList< Width > &rhs)
Transfer the contents of the argument list into this list and annul the argument list.
Definition: PackedListI.H:669
bool trim(label minpos=-1)
Trim any trailing zero elements, optionally specifying a a minimum position, below which trimming wil...
Definition: PackedListI.H:90
void operator=(const PackedList< Width > &list)
Copy assignment.
Definition: PackedListI.H:838
label capacity() const noexcept
Number of elements that can be stored without reallocating.
Definition: PackedListI.H:437
unsigned int get(const label i) const
Get value at index i or 0 for out-of-range.
Definition: PackedListI.H:683
void shrink()
Shrink the allocated space to what is actually used.
Definition: PackedListI.H:574
reference(PackedList *parent, const label index)
Construct by taking reference of block from within the list and the specified index.
label size() const noexcept
Number of entries.
Definition: PackedList.H:371
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:419
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:760