Go to the documentation of this file.
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>
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);
147 return (val ? ~0u : 0u);
165 template<
unsigned W
idth>
173 template<
unsigned W
idth>
176 blocks_(num_blocks(numElem), 0u),
181 template<
unsigned W
idth>
185 const unsigned int val
188 blocks_(num_blocks(numElem), 0u),
198 template<
unsigned W
idth>
208 template<
unsigned W
idth>
211 blocks_(list.blocks_),
216 template<
unsigned W
idth>
219 blocks_(std::move(list.blocks_)),
226 template<
unsigned W
idth>
229 blocks_(num_blocks(
values.size()), 0u),
232 const label len =
values.size();
237 for (label i = 0; i < len; ++i)
239 const unsigned int val(
values[i]);
240 if (val) set(i, val);
245 template<
unsigned W
idth>
252 blocks_(num_blocks(
values.size()), 0u),
255 const label len =
values.size();
260 for (label i = 0; i < len; ++i)
262 const unsigned int val(
values[i]);
263 if (val) set(i, val);
268 template<
unsigned W
idth>
278 template<
unsigned W
idth>
285 ref_(parent->blocks_[index / elem_per_block]),
286 shift_(Width * (index % elem_per_block))
290 template<
unsigned W
idth>
297 template<
unsigned W
idth>
300 const unsigned int mask = (
max_value << shift_);
301 const unsigned int prev = ref_;
310 ref_ |= mask & (val << shift_);
313 return (prev != ref_);
317 template<
unsigned W
idth>
324 this->
set(other.get());
328 template<
unsigned W
idth>
331 const unsigned int val
338 template<
unsigned W
idth>
347 template<
unsigned W
idth>
353 <<
"attempt to access element " << i <<
" from zero sized list"
356 else if (i < 0 || i >=
size_)
359 <<
"index " << i <<
" out of range [0," <<
size_ <<
")"
365 template<
unsigned W
idth>
372 template<
unsigned W
idth>
379 template<
unsigned W
idth>
386 template<
unsigned W
idth>
390 const unsigned int val
395 const label oldSize =
size();
398 if (oldSize <
size())
409 for (label blocki = oldLen; blocki < newLen; ++blocki)
423 blocks_[blk] |= ~mask & blockval;
430 else if (
size() < oldSize)
439 for (label blocki = newLen; blocki < oldLen; ++blocki)
449 template<
unsigned W
idth>
453 const unsigned int val
460 template<
unsigned W
idth>
467 if (numElem <
size())
475 template<
unsigned W
idth>
478 const label oldLen =
blocks_.size();
487 max(16,
max(newLen, 2*oldLen)),
494 template<
unsigned W
idth>
501 template<
unsigned W
idth>
509 template<
unsigned W
idth>
517 template<
unsigned W
idth>
529 template<
unsigned W
idth>
536 template<
unsigned W
idth>
543 template<
unsigned W
idth>
550 template<
unsigned W
idth>
557 template<
unsigned W
idth>
570 template<
unsigned W
idth>
584 template<
unsigned W
idth>
587 if (i < 0 || i >=
size())
593 <<
"Ignoring attempt to get a negative index " << i
594 <<
" range is [0," <<
size_ <<
")"
606 template<
unsigned W
idth>
610 const unsigned int val
617 <<
"Ignoring attempt to set a negative index " << i
618 <<
" range is [0," <<
size_ <<
")"
624 else if (i >=
size())
634 return reference(
this, i).set(val);
638 template<
unsigned W
idth>
641 if (i < 0 || i >=
size())
646 return reference(
this, i).set(0u);
650 template<
unsigned W
idth>
654 const label idx =
size();
658 reference(
this, idx).set(val);
663 template<
unsigned W
idth>
667 const label idx =
size()-1;
675 const unsigned int old = reference(
this, idx).get();
682 template<
unsigned W
idth>
694 for (label blocki=0; blocki < nblocks; ++blocki)
704 for (label blocki=0; blocki < nblocks; ++blocki)
713 template<
unsigned W
idth>
723 template<
unsigned W
idth>
730 template<
unsigned W
idth>
737 return reference(
this, i);
741 template<
unsigned W
idth>
748 template<
unsigned W
idth>
755 template<
unsigned W
idth>
764 template<
unsigned W
idth>
765 inline bool Foam::operator==
775 template<
unsigned W
idth>
776 inline bool Foam::operator!=
void reset()
Clear all bits but do not adjust the addressable size.
bool set(unsigned int val)
Set value, returning true if changed, no range-checking.
block_type & ref_
Reference to the block.
A reference supporting read/write access to an entry.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
autoPtr< PackedList< Width > > clone() const
Clone.
unsigned int block_type
The storage block type for bit elements.
reference(PackedList *parent, const label index)
label nBlocks() const
The number of internal storage blocks.
void clear_trailing_bits()
Clear any partial rubbish in the last addressable block.
bool empty() const noexcept
True if the list is empty (ie, size() is zero).
Ostream & endl(Ostream &os)
Add newline and flush stream.
constexpr PackedList() noexcept
Default construct, zero-sized and no allocation.
bool readEnd(const char *funcName)
End read of data chunk, ends with ')'.
void Swap(DynamicList< T, SizeMin1 > &a, DynamicList< T, SizeMin2 > &b)
void checkIndex(const label i) const
Check index is within valid range [0,size)
void resize(const label nElem, const unsigned int val=0u)
Reset addressable list size, does not shrink the allocated size.
void swap(PackedList< Width > &rhs)
Swap contents with argument.
unsigned int get(const label i) const
Get value at index i or 0 for out-of-range.
unsigned int get() const
Get value as unsigned, no range-checking.
bool readBegin(const char *funcName)
Begin read of data chunk, starts with '('.
static constexpr block_type mask_lower(unsigned elementOffset)
Masking for all bits below the element offset.
label size_
Number of entries used.
block_container blocks_
The blocks of raw data.
static unsigned int repeated_value(unsigned val)
A fill value for complete blocks.
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
bool readBool(Istream &is)
Read bool from stream using Foam::Switch(Istream&)
void setCapacity(const label nElem)
Alter the size of the underlying storage.
void operator=(const unsigned int val)
Assignment of all entries to the given value. Takes linear time.
void transfer(List< T > &list)
bool unset(const label i)
Unset the entry at index i.
unsigned int remove()
Remove and return the last element.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
void resize(const label newSize)
Adjust allocated size of list.
static constexpr label num_blocks(label numElem)
std::streamsize byteSize() const
unsigned int operator[](const label i) const
Identical to get() - get value at index.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
void transfer(PackedList< Width > &rhs)
Transfer the contents of the argument list into this list.
errorManip< error > abort(error &err)
PackedList< Width > & append(const unsigned int val)
Append a value at the end of the list.
bool equal(const PackedList< Width > &other) const
Test for equality of sizes and the bits set.
void setPair(Istream &is)
Read an index/value pair and set accordingly.
void assign(const unsigned int val)
Assign all entries to the given value. Takes linear time.
static constexpr block_type max_value
errorManipArg< error, int > exit(error &err, const int errNo=1)
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
label capacity() const
The number of elements that can be stored with reallocating.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
void setSize(const label nElem, const unsigned int val=0u)
Alias for resize()
static constexpr unsigned elem_per_block
The number of elements stored per data block.
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
A dynamic list of packed unsigned integers, with the number of bits per item specified by the <Width>...
label size() const noexcept
Number of entries.
void reserve(const label nElem)
Reserve allocation space for at least this size.
void clear()
Clear the list, i.e. set size to zero.
bool trim(label minpos=-1)
const List< unsigned int > & storage() const
Return the underlying storage blocks.
void clearStorage()
Clear the list and delete storage.
bool set(const label i, unsigned int val=~0u)
Set value at index i, default value set is the max_value.
void shrink()
Shrink the allocated space to what is actually used.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Base for lists with indirect addressing, templated on the list contents type and the addressing type....
unsigned shift_
The bit shift to access the given sub-portion.
#define WarningInFunction
Report a warning using Foam::Warning.
void clear()
Clear the list, i.e. set addressable size to zero.
static unsigned int readValue(Istream &is)
Read a list entry (allows for specialization)