33 template<
unsigned W
idth>
36 return BitOps::repeat_value<block_type,Width>(val);
40 template<
unsigned W
idth>
48 <<
"Out-of-range value " << val <<
" for PackedList<" << Width
49 <<
">. Maximum permitted value is " << max_value <<
"." 57 template<
unsigned W
idth>
60 is.readBegin(
"Tuple2<label,uint32>");
65 is.readEnd(
"Tuple2<label,uint32>");
70 <<
"Out-of-range value " << val <<
" for PackedList<" << Width
71 <<
"> at index " << ind
72 <<
". Maximum permitted value is " << max_value <<
"." 82 template<
unsigned W
idth>
86 const unsigned int blk = size() / elem_per_block;
87 const unsigned int off = size() % elem_per_block;
91 blocks_[blk] &= mask_lower(off);
96 template<
unsigned W
idth>
104 const label orig = size();
110 for (label blocki = num_blocks(size())-1; blocki >= 0; --blocki)
113 size_ = blocki * elem_per_block;
115 unsigned int blockval = blocks_[blocki];
120 for (; blockval; ++size_)
126 else if (size_ < minpos)
137 return (size() != orig);
141 template<
unsigned W
idth>
145 blocks_ = rhs.blocks_;
150 template<
unsigned W
idth>
155 const label nblocks = num_blocks(size());
157 for (label blocki=0; blocki < nblocks; ++blocki)
170 template<
unsigned W
idth>
181 const label nblocks = num_blocks(size());
184 const unsigned int off = size() % elem_per_block;
188 for (label blocki=0; blocki < nblocks; ++blocki)
190 if (~(blocks_[blocki]))
198 for (label blocki=0; blocki < nblocks-1; ++blocki)
200 if (~(blocks_[blocki]))
207 if (~(blocks_[nblocks-1]) & mask_lower(off))
225 return (val ? ~0u : 0u);
243 template<
unsigned W
idth>
251 template<
unsigned W
idth>
254 blocks_(num_blocks(numElem), 0u),
259 template<
unsigned W
idth>
263 const unsigned int val
266 blocks_(num_blocks(numElem), 0u),
276 template<
unsigned W
idth>
286 template<
unsigned W
idth>
289 blocks_(list.blocks_),
294 template<
unsigned W
idth>
297 blocks_(
std::move(list.blocks_)),
304 template<
unsigned W
idth>
307 blocks_(num_blocks(
values.size()), 0u),
310 const label len =
values.size();
315 for (label i = 0; i < len; ++i)
317 const unsigned int val(
values[i]);
318 if (val)
set(i, val);
323 template<
unsigned W
idth>
327 const IndirectListBase<label, Addr>&
values 330 blocks_(num_blocks(
values.size()), 0u),
333 const label len =
values.size();
338 for (label i = 0; i < len; ++i)
340 const unsigned int val(
values[i]);
341 if (val)
set(i, val);
346 template<
unsigned W
idth>
350 return autoPtr<PackedList<Width>>
::New(*
this);
356 template<
unsigned W
idth>
359 PackedList<Width>* parent,
363 ref_(parent->blocks_[index / elem_per_block]),
364 shift_(Width * (index % elem_per_block))
368 template<
unsigned W
idth>
375 template<
unsigned W
idth>
378 const unsigned int mask = (
max_value << shift_);
379 const unsigned int prev = ref_;
388 ref_ |= mask & (val << shift_);
391 return (prev != ref_);
395 template<
unsigned W
idth>
402 this->
set(other.get());
406 template<
unsigned W
idth>
409 const unsigned int val
416 template<
unsigned W
idth>
425 template<
unsigned W
idth>
431 <<
"attempt to access element " << i <<
" from zero sized list" 434 else if (i < 0 || i >=
size_)
437 <<
"index " << i <<
" out of range [0," <<
size_ <<
")" 443 template<
unsigned W
idth>
450 template<
unsigned W
idth>
460 template<
unsigned W
idth>
464 const unsigned int val
469 const label oldSize =
size();
472 if (oldSize < newSize)
483 for (label blocki = oldLen; blocki < newLen; ++blocki)
497 blocks_[blk] |= ~mask & blockval;
504 else if (newSize < oldSize)
513 for (label blocki = newLen; blocki < oldLen; ++blocki)
523 template<
unsigned W
idth>
530 if (numElem <
size())
538 template<
unsigned W
idth>
550 max(16,
max(newLen, 2*oldLen)),
557 template<
unsigned W
idth>
564 template<
unsigned W
idth>
572 template<
unsigned W
idth>
580 template<
unsigned W
idth>
592 template<
unsigned W
idth>
599 template<
unsigned W
idth>
606 template<
unsigned W
idth>
613 template<
unsigned W
idth>
620 template<
unsigned W
idth>
627 template<
unsigned W
idth>
634 template<
unsigned W
idth>
641 template<
unsigned W
idth>
648 template<
unsigned W
idth>
655 template<
unsigned W
idth>
662 template<
unsigned W
idth>
675 template<
unsigned W
idth>
689 template<
unsigned W
idth>
692 if (i < 0 || i >=
size())
698 <<
"Ignoring attempt to get a negative index " << i
699 <<
" range is [0," <<
size_ <<
")" 711 template<
unsigned W
idth>
715 const unsigned int val
722 <<
"Ignoring attempt to set a negative index " << i
723 <<
" range is [0," <<
size_ <<
")" 729 else if (i >=
size())
739 return reference(
this, i).set(val);
743 template<
unsigned W
idth>
746 if (i < 0 || i >=
size())
751 return reference(
this, i).set(0u);
755 template<
unsigned W
idth>
758 const label idx =
size();
762 reference(
this, idx).set(val);
766 template<
unsigned W
idth>
780 template<
unsigned W
idth>
784 const label idx =
size()-1;
792 const unsigned int old = reference(
this, idx).get();
799 template<
unsigned W
idth>
812 for (label blocki=0; blocki < nblocks; ++blocki)
826 template<
unsigned W
idth>
833 template<
unsigned W
idth>
840 return reference(
this, i);
844 template<
unsigned W
idth>
851 template<
unsigned W
idth>
858 template<
unsigned W
idth>
867 template<
unsigned W
idth>
868 inline bool Foam::operator==
870 const PackedList<Width>& a,
871 const PackedList<Width>&
b 878 template<
unsigned W
idth>
879 inline bool Foam::operator!=
881 const PackedList<Width>& a,
882 const PackedList<Width>&
b void setCapacity(const label numElem)
Alter the size of the underlying storage.
void swap(UList< T > &list) noexcept
Swap content with another UList of the same type in constant time.
std::streamsize size_data() const noexcept
The number of integer blocks addressed in the raw storage.
void size(const label n)
Older name for setAddressableSize.
unsigned int get() const
Get value as unsigned, no range-checking.
errorManipArg< error, int > exit(error &err, const int errNo=1)
bool unset(const label i)
Unset the entry at index i.
void resize(const label len)
Adjust allocated size of list.
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument list.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
std::streamsize byteSize() const noexcept
The number of bytes used in the raw storage including any unused padding.
const char * cdata_bytes() const noexcept
A const pointer to the raw storage, reinterpreted as byte data.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
std::streamsize size_bytes() const noexcept
The number of bytes used in the raw storage including any unused padding.
autoPtr< PackedList< Width > > clone() const
Clone.
const List< unsigned int > & storage() const
Return the underlying storage blocks.
T * data() noexcept
Return pointer to the underlying array serving as data storage.
Ostream & endl(Ostream &os)
Add newline and flush stream.
unsigned int remove()
Remove and return the last element.
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.
unsigned int operator[](const label i) const
Identical to get() - get value at index.
void setPair(Istream &is)
Read an index/value pair and set accordingly.
char * data_bytes() noexcept
Return pointer to the underlying array serving as data storage,.
A reference supporting read/write access to an entry.
label nBlocks() const
The number of internal storage blocks.
void resize(const label numElem, const unsigned int val=0u)
Reset addressable list size, does not shrink the allocated size.
label first_block() const
Find the first block with a '1' bit.
const char * cdata_bytes() const noexcept
Return pointer to the underlying array serving as data storage,.
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...
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
constexpr PackedList() noexcept
Default construct, zero-sized and no allocation.
A dynamic list of packed unsigned integers, with the number of bits per item specified by the <Width>...
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
void clear()
Clear the list, i.e. set size to zero.
void fill(const unsigned int val)
Assign all entries to the given value.
static unsigned int readValue(Istream &is)
Read a list entry (allows for specialization)
label size_
Number of entries used.
bool set(unsigned int val)
Set value, returning true if changed, no range-checking.
bool set(const label i, unsigned int val=~0u)
Set value at index i, default value set is the max_value.
errorManip< error > abort(error &err)
void clear()
Clear the list, i.e. set addressable size to zero.
label first_not_block() const
Find the first block with a '0' bit.
void reserve(const label numElem)
Reserve allocation space for at least this size (uses a size doubling strategy).
unsigned shift_
The bit shift to access the given sub-portion.
block_type & ref_
Reference to the block.
void swap(PackedList< Width > &rhs)
Swap contents with argument.
static constexpr block_type max_value
The max value for an element which is also the bit-mask of the individual element.
unsigned int block_type
The storage block type for bit elements.
bool empty() const noexcept
True if the list is empty (ie, size() is zero).
char * data_bytes() noexcept
A pointer to the raw storage, reinterpreted as byte data.
#define WarningInFunction
Report a warning using Foam::Warning.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
void resize_nocopy(const label numElem)
Currently identical to resize. Subject to future change (Oct-2021)
unsigned int * data() noexcept
A pointer to the raw storage.
block_container blocks_
The blocks of raw data.
static constexpr block_type mask_lower(unsigned elementOffset)
Masking for all bits below the element offset.
void push_back(const unsigned int val)
Append a value at the end of the list.
void clearStorage()
Clear the list and delete storage.
void copyAssign(const PackedList< Width > &rhs)
Copy assignment.
static constexpr label num_blocks(label numElem) noexcept
Calculate the number of blocks required to _address_ the requested number of elements.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
const T * cdata() const noexcept
Return pointer to the underlying array serving as data storage.
void reset()
Clear all bits but do not adjust the addressable size.
static constexpr unsigned elem_per_block
The number of elements stored per data block.
void clear_trailing_bits()
Clear any partial rubbish in the last addressable block.
const unsigned int * cdata() const noexcept
A const pointer to the raw storage.
void transfer(PackedList< Width > &rhs)
Transfer the contents of the argument list into this list and annul the argument list.
bool trim(label minpos=-1)
Trim any trailing zero elements, optionally specifying a a minimum position, below which trimming wil...
void operator=(const PackedList< Width > &list)
Copy assignment.
label capacity() const noexcept
Number of elements that can be stored without reallocating.
unsigned int get(const label i) const
Get value at index i or 0 for out-of-range.
void shrink()
Shrink the allocated space to what is actually used.
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.
bool readBool(Istream &is)
Read bool from stream using Foam::Switch(Istream&)
void checkIndex(const label i) const
Check index is within valid range [0,size)
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
void pop_back(label n=1)
Reduce size by 1 or more elements. Can be called on an empty list.