33template<
unsigned W
idth>
40template<
unsigned W
idth>
48 <<
"Out-of-range value " << val <<
" for PackedList<" << Width
49 <<
">. Maximum permitted value is " << max_value <<
"."
57template<
unsigned W
idth>
60 is.readBegin(
"Tuple2<label,uint32>");
62 const label ind = readLabel(is);
63 const unsigned int val = readLabel(is);
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 <<
"."
73 << exit(FatalIOError);
82template<
unsigned W
idth>
86 const unsigned int blk = size() / elem_per_block;
87 const unsigned int off = size() % elem_per_block;
96template<
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);
141template<
unsigned W
idth>
150template<
unsigned W
idth>
155 const label nblocks = num_blocks(size());
157 for (label blocki=0; blocki < nblocks; ++blocki)
170template<
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);
243template<
unsigned W
idth>
251template<
unsigned W
idth>
259template<
unsigned W
idth>
263 const unsigned int val
266 blocks_(num_blocks(numElem), 0u),
276template<
unsigned W
idth>
286template<
unsigned W
idth>
294template<
unsigned W
idth>
304template<
unsigned W
idth>
307 blocks_(num_blocks(values.size()), 0u),
315 for (label i = 0; i < len; ++i)
317 const unsigned int val(
values[i]);
323template<
unsigned W
idth>
327 const IndirectListBase<label, Addr>& values
330 blocks_(num_blocks(values.size()), 0u),
338 for (label i = 0; i < len; ++i)
340 const unsigned int val(
values[i]);
346template<
unsigned W
idth>
350 return autoPtr<PackedList<Width>>
::New(*
this);
356template<
unsigned W
idth>
368template<
unsigned W
idth>
375template<
unsigned W
idth>
378 const unsigned int mask = (max_value << shift_);
379 const unsigned int prev = ref_;
381 if (val >= max_value)
388 ref_ |= mask & (val << shift_);
391 return (prev != ref_);
395template<
unsigned W
idth>
398 const reference& other
402 this->
set(other.get());
406template<
unsigned W
idth>
409 const unsigned int val
416template<
unsigned W
idth>
425template<
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_ <<
")"
443template<
unsigned W
idth>
450template<
unsigned W
idth>
460template<
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;
501 clear_trailing_bits();
504 else if (newSize < oldSize)
513 for (label blocki = newLen; blocki < oldLen; ++blocki)
523template<
unsigned W
idth>
538template<
unsigned W
idth>
541 const label oldLen =
blocks_.size();
557template<
unsigned W
idth>
560 const label oldLen =
blocks_.size();
576template<
unsigned W
idth>
583template<
unsigned W
idth>
591template<
unsigned W
idth>
599template<
unsigned W
idth>
611template<
unsigned W
idth>
618template<
unsigned W
idth>
625template<
unsigned W
idth>
632template<
unsigned W
idth>
639template<
unsigned W
idth>
646template<
unsigned W
idth>
653template<
unsigned W
idth>
666template<
unsigned W
idth>
680template<
unsigned W
idth>
683 if (i < 0 || i >= size())
689 <<
"Ignoring attempt to get a negative index " << i
690 <<
" range is [0," << size_ <<
")"
702template<
unsigned W
idth>
706 const unsigned int val
713 <<
"Ignoring attempt to set a negative index " << i
714 <<
" range is [0," << size_ <<
")"
720 else if (i >=
size())
730 return reference(
this, i).set(val);
734template<
unsigned W
idth>
737 if (i < 0 || i >= size())
746template<
unsigned W
idth>
749 const label idx =
size();
757template<
unsigned W
idth>
771template<
unsigned W
idth>
775 const label idx = size()-1;
783 const unsigned int old = reference(
this, idx).get();
790template<
unsigned W
idth>
798 const label nblocks = num_blocks(size());
801 const unsigned int blockval = (val ? repeated_value(val) : 0u);
803 for (label blocki=0; blocki < nblocks; ++blocki)
805 blocks_[blocki] = blockval;
810 clear_trailing_bits();
817template<
unsigned W
idth>
824template<
unsigned W
idth>
835template<
unsigned W
idth>
842template<
unsigned W
idth>
849template<
unsigned W
idth>
858template<
unsigned W
idth>
859inline bool Foam::operator==
861 const PackedList<Width>& a,
862 const PackedList<Width>&
b
869template<
unsigned W
idth>
870inline bool Foam::operator!=
872 const PackedList<Width>& a,
873 const PackedList<Width>&
b
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Base for lists with indirect addressing, templated on the list contents type and the addressing type....
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
bool readEnd(const char *funcName)
End read of data chunk, ends with ')'.
bool readBegin(const char *funcName)
Begin read of data chunk, starts with '('.
A reference supporting read/write access to an entry.
reference(PackedList *parent, const label index)
Construct by taking reference of block from within the list and the specified index.
unsigned shift_
The bit shift to access the given sub-portion.
block_type & ref_
Reference to the block.
unsigned int get() const
Get value as unsigned, no range-checking.
bool set(unsigned int val)
Set value, returning true if changed, no range-checking.
A dynamic list of packed unsigned integers, with the number of bits per item specified by the <Width>...
label num_blocks() const noexcept
The number of internal storage blocks.
void copyAssign(const PackedList< Width > &rhs)
Copy assignment.
label size_
Number of entries used.
std::streamsize size_data() const noexcept
The number of integer blocks addressed in the raw storage. Same as num_blocks().
static unsigned int readValue(Istream &is)
Read a list entry (allows for specialization).
void pop_back(label n=1)
Reduce size by 1 or more elements. Can be called on an empty list.
label first_block() const
Find the first block with a '1' bit.
void swap(PackedList< Width > &rhs)
Swap contents with argument.
bool unset(const label i)
Unset the entry at index i.
char * data_bytes() noexcept
A pointer to the raw storage, reinterpreted as byte data.
void checkIndex(const label i) const
Check index is within valid range [0,size).
bool equal(const PackedList< Width > &other) const
Test for equality of sizes and the bits set.
static constexpr block_type mask_lower(unsigned elementOffset)
Masking for all bits below the element offset.
block_container blocks_
The blocks of raw data.
bool empty() const noexcept
True if the list is empty (ie, size() is zero).
void push_back(const unsigned int val)
Append a value at the end of the list.
labelList values() const
Return the values as a list of labels.
void resize_nocopy(const label numElem)
Currently identical to resize. Subject to future change (Oct-2021).
autoPtr< PackedList< Width > > clone() const
Clone.
void resize(const label numElem, const unsigned int val=0u)
Reset addressable list size, does not shrink the allocated size.
void fill(const unsigned int val)
Assign all entries to the given value.
void shrink_to_fit()
Shrink the allocated space to what is actually used.
static constexpr block_type max_value
The max value for an element which is also the bit-mask of the individual element.
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...
void setCapacity(const label numElem)
Alter the size of the underlying storage.
void clear_trailing_bits()
Clear any partial rubbish in the last addressable block.
std::streamsize byteSize() const noexcept
Same as size_bytes().
void clearStorage()
Clear the list and delete storage.
void operator=(const PackedList< Width > &list)
Copy assignment.
label capacity() const noexcept
Number of elements that can be stored without reallocating.
bool set(const label i, unsigned int val=~0u)
Set value at index i, default value set is the max_value.
bool trim(label minpos=-1)
Trim any trailing zero elements, optionally specifying a a minimum position, below which trimming wil...
void reserve(const label numElem)
Reserve allocation space for at least this size (uses a size doubling strategy).
unsigned int get(const label i) const
Get value at index i or 0 for out-of-range.
constexpr PackedList() noexcept
Default construct, zero-sized and no allocation.
static constexpr unsigned elem_per_block
The number of elements stored per data block.
void transfer(PackedList< Width > &rhs)
Transfer the contents of the argument list into this list and annul the argument list.
const char * cdata_bytes() const noexcept
A const pointer to the raw storage, reinterpreted as byte data.
static constexpr label num_blocks(label numElem) noexcept
Calculate the number of blocks required to _address_ the requested number of elements.
void setPair(Istream &is)
Read an index/value pair and set accordingly.
label size() const noexcept
Number of entries.
unsigned int block_type
The storage block type for bit elements.
void clear()
Clear the list, i.e. set addressable size to zero.
Istream & readList(Istream &is)
Clear list and read from stream.
void reset()
Clear all bits but do not adjust the addressable size.
void reserve_exact(const label numElem)
Reserve allocation space for at least this size (uses the specified size without any other resizing s...
label first_not_block() const
Find the first block with a '0' bit.
std::streamsize size_bytes() const noexcept
The number of bytes addressed in the raw storage including any padding.
unsigned int operator[](const label i) const
Identical to get() - get value at index.
unsigned int remove()
Remove and return the last element.
void size(const label n)
Older name for setAddressableSize.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
limits reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL))
patchWriters resize(patchIds.size())
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
#define WarningInFunction
Report a warning using Foam::Warning.
UIntType repeat_value(unsigned val)
Repeat a value of the given BitWidth into the destination output type.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
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.
Ostream & endl(Ostream &os)
Add newline and flush stream.
errorManip< error > abort(error &err)
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
UList< label > labelUList
A UList of labels.
bool readBool(Istream &is)
Read bool from stream using Foam::Switch(Istream&).
triangles reserve(surf.size())