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>
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_;
158 return (val ? ~0u : 0u);
176 template<
unsigned W
idth>
184 template<
unsigned W
idth>
187 blocks_(num_blocks(numElem), 0u),
192 template<
unsigned W
idth>
196 const unsigned int val
199 blocks_(num_blocks(numElem), 0u),
209 template<
unsigned W
idth>
219 template<
unsigned W
idth>
222 blocks_(list.blocks_),
227 template<
unsigned W
idth>
230 blocks_(std::move(list.blocks_)),
237 template<
unsigned W
idth>
240 blocks_(num_blocks(
values.size()), 0u),
243 const label len =
values.size();
248 for (label i = 0; i < len; ++i)
250 const unsigned int val(
values[i]);
251 if (val)
set(i, val);
256 template<
unsigned W
idth>
260 const IndirectListBase<label, Addr>&
values
263 blocks_(num_blocks(
values.size()), 0u),
266 const label len =
values.size();
271 for (label i = 0; i < len; ++i)
273 const unsigned int val(
values[i]);
279 template<
unsigned W
idth>
283 return autoPtr<PackedList<Width>>
::New(*
this);
289 template<
unsigned W
idth>
292 PackedList<Width>* parent,
296 ref_(parent->blocks_[index / elem_per_block]),
297 shift_(Width * (index % elem_per_block))
301 template<
unsigned W
idth>
308 template<
unsigned W
idth>
311 const unsigned int mask = (
max_value << shift_);
312 const unsigned int prev = ref_;
321 ref_ |= mask & (val << shift_);
324 return (prev != ref_);
328 template<
unsigned W
idth>
335 this->
set(other.get());
339 template<
unsigned W
idth>
342 const unsigned int val
349 template<
unsigned W
idth>
358 template<
unsigned W
idth>
364 <<
"attempt to access element " << i <<
" from zero sized list"
367 else if (i < 0 || i >=
size_)
370 <<
"index " << i <<
" out of range [0," <<
size_ <<
")"
376 template<
unsigned W
idth>
383 template<
unsigned W
idth>
390 template<
unsigned W
idth>
397 template<
unsigned W
idth>
407 template<
unsigned W
idth>
411 const unsigned int val
416 const label oldSize =
size();
419 if (oldSize < newSize)
430 for (label blocki = oldLen; blocki < newLen; ++blocki)
444 blocks_[blk] |= ~mask & blockval;
451 else if (newSize < oldSize)
460 for (label blocki = newLen; blocki < oldLen; ++blocki)
470 template<
unsigned W
idth>
477 if (numElem <
size())
485 template<
unsigned W
idth>
488 const label oldLen =
blocks_.size();
497 max(16,
max(newLen, 2*oldLen)),
504 template<
unsigned W
idth>
511 template<
unsigned W
idth>
519 template<
unsigned W
idth>
527 template<
unsigned W
idth>
539 template<
unsigned W
idth>
546 template<
unsigned W
idth>
553 template<
unsigned W
idth>
560 template<
unsigned W
idth>
567 template<
unsigned W
idth>
574 template<
unsigned W
idth>
581 template<
unsigned W
idth>
588 template<
unsigned W
idth>
595 template<
unsigned W
idth>
602 template<
unsigned W
idth>
615 template<
unsigned W
idth>
629 template<
unsigned W
idth>
632 if (i < 0 || i >=
size())
638 <<
"Ignoring attempt to get a negative index " << i
639 <<
" range is [0," <<
size_ <<
")"
651 template<
unsigned W
idth>
655 const unsigned int val
662 <<
"Ignoring attempt to set a negative index " << i
663 <<
" range is [0," <<
size_ <<
")"
669 else if (i >=
size())
679 return reference(
this, i).set(val);
683 template<
unsigned W
idth>
686 if (i < 0 || i >=
size())
691 return reference(
this, i).set(0u);
695 template<
unsigned W
idth>
699 const label idx =
size();
703 reference(
this, idx).set(val);
708 template<
unsigned W
idth>
712 const label idx =
size()-1;
720 const unsigned int old = reference(
this, idx).get();
727 template<
unsigned W
idth>
740 for (label blocki=0; blocki < nblocks; ++blocki)
754 template<
unsigned W
idth>
761 template<
unsigned W
idth>
768 return reference(
this, i);
772 template<
unsigned W
idth>
779 template<
unsigned W
idth>
786 template<
unsigned W
idth>
795 template<
unsigned W
idth>
796 inline bool Foam::operator==
798 const PackedList<Width>& a,
799 const PackedList<Width>&
b
806 template<
unsigned W
idth>
807 inline bool Foam::operator!=
809 const PackedList<Width>& a,
810 const PackedList<Width>&
b
void resize(const label numElem, const unsigned int val=0u)
bool set(unsigned int val)
void set(List< bool > &bools, const labelRange &range)
void reserve(const label numElem)
void resize(const label len)
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
autoPtr< PackedList< Width > > clone() const
reference(PackedList *parent, const label index)
std::streamsize size_bytes() const noexcept
void clear_trailing_bits()
bool empty() const noexcept
Ostream & endl(Ostream &os)
constexpr PackedList() noexcept
bool readEnd(const char *funcName)
void checkIndex(const label i) const
void swap(PackedList< Width > &rhs)
unsigned int get(const label i) const
bool readBegin(const char *funcName)
const char * cdata_bytes() const noexcept
static constexpr block_type mask_lower(unsigned elementOffset)
unsigned int * data() noexcept
static unsigned int repeated_value(unsigned val)
const dimensionedScalar b
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
bool readBool(Istream &is)
void transfer(List< T > &list)
bool unset(const label i)
label max(const labelHashSet &set, label maxValue=labelMin)
void fill(const unsigned int val)
const unsigned int * cdata() const noexcept
unsigned int operator[](const label i) const
virtual bool check(const char *operation) const
void transfer(PackedList< Width > &rhs)
errorManip< error > abort(error &err)
PackedList< Width > & append(const unsigned int val)
bool equal(const PackedList< Width > &other) const
void setPair(Istream &is)
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)
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
#define FatalErrorInFunction
static constexpr unsigned elem_per_block
label readLabel(const char *buf)
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>...
void operator=(const PackedList< Width > &lst)
label size() const noexcept
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
bool trim(label minpos=-1)
const List< unsigned int > & storage() const
char * data_bytes() noexcept
bool set(const label i, unsigned int val=~0u)
#define FatalIOErrorInFunction(ios)
Base for lists with indirect addressing, templated on the list contents type and the addressing type....
std::streamsize byteSize() const noexcept
void resize_nocopy(const label numElem)
label capacity() const noexcept
void copyAssign(const PackedList< Width > &rhs)
#define WarningInFunction
static constexpr label num_blocks(label numElem) noexcept
static unsigned int readValue(Istream &is)
void setCapacity(const label numElem)