Go to the documentation of this file.
31 template<
unsigned nBits>
38 template<
unsigned nBits>
41 return (1u << nBits) - 1;
45 template<
unsigned nBits>
52 template<
unsigned nBits>
58 return (~0u >> (
sizeof(
StorageType)*CHAR_BIT - nBits * offset));
62 template<
unsigned nBits>
65 return (nElem + packing() - 1) / packing();
103 template<
unsigned nBits>
108 if (val > max_value())
111 <<
"Out-of-range value " << val <<
" for PackedList<" << nBits
112 <<
">. Maximum permitted value is " << max_value() <<
"."
120 template<
unsigned nBits>
123 is.readBegin(
"Tuple2<label, unsigned int>");
128 is.readEnd(
"Tuple2<label, unsigned int>");
130 if (val > max_value())
133 <<
"Out-of-range value " << val <<
" for PackedList<" << nBits
134 <<
"> at index " << ind
135 <<
". Maximum permitted value is " << max_value() <<
"."
142 is.check(
"PackedList<nBits>::setPair(Istream&)");
146 template<
unsigned nBits>
168 template<
unsigned nBits>
177 template<
unsigned nBits>
186 template<
unsigned nBits>
190 const unsigned int val
194 StorageList(packedLength(size), 0u),
204 template<
unsigned nBits>
215 template<
unsigned nBits>
224 template<
unsigned nBits>
231 template<
unsigned nBits>
235 StorageList(packedLength(lst.size()), 0u),
245 template<
unsigned nBits>
249 StorageList(packedLength(lst.size()), 0u),
259 template<
unsigned nBits>
271 template<
unsigned nBits>
279 template<
unsigned nBits>
291 template<
unsigned nBits>
295 const unsigned int seg = index_ /
packing();
296 const unsigned int off = index_ %
packing();
298 const unsigned int& stored = list_->StorageList::operator[](seg);
299 return (stored >> (nBits * off)) &
max_value();
303 template<
unsigned nBits>
307 const unsigned int seg = index_ /
packing();
308 const unsigned int off = index_ %
packing();
310 const unsigned int startBit = nBits * off;
311 const unsigned int mask =
max_value() << startBit;
313 unsigned int& stored = list_->StorageList::operator[](seg);
314 const unsigned int prev = stored;
324 stored |= mask & (val << startBit);
327 return prev != stored;
331 template<
unsigned nBits>
338 template<
unsigned nBits>
344 return this->
get() == iter.
get();
348 template<
unsigned nBits>
354 return this->
get() != iter.
get();
358 template<
unsigned nBits>
362 const unsigned int val = iter.
get();
368 template<
unsigned nBits>
373 if (index_ >= list_->size_)
375 list_->resize(index_ + 1);
383 template<
unsigned nBits>
385 unsigned int ()
const
388 if (index_ >= list_->size_)
399 template<
unsigned nBits>
406 template<
unsigned nBits>
413 template<
unsigned nBits>
430 template<
unsigned nBits>
433 const iteratorBase& iter
447 template<
unsigned nBits>
450 const PackedList<nBits>* lst,
458 template<
unsigned nBits>
461 const PackedList<nBits>* lst,
469 template<
unsigned nBits>
475 iteratorBase(static_cast<const iteratorBase&>(iter))
479 template<
unsigned nBits>
485 return this->index_ == iter.index_;
489 template<
unsigned nBits>
495 return this->index_ != iter.index_;
499 template<
unsigned nBits>
505 return this->index_ == iter.index_;
509 template<
unsigned nBits>
515 return this->index_ != iter.index_;
519 template<
unsigned nBits>
523 this->list_ = iter.
list_;
524 this->index_ = iter.
index_;
528 if (this->index_ > this->list_->size_)
530 this->index_ = this->list_->size_;
537 template<
unsigned nBits>
541 this->list_ = iter.
list_;
542 this->index_ = iter.
index_;
546 if (this->index_ > this->list_->size_)
548 this->index_ = this->list_->size_;
555 template<
unsigned nBits>
564 template<
unsigned nBits>
573 template<
unsigned nBits>
583 template<
unsigned nBits>
593 template<
unsigned nBits>
602 template<
unsigned nBits>
611 template<
unsigned nBits>
621 template<
unsigned nBits>
631 template<
unsigned nBits>
639 template<
unsigned nBits>
647 template<
unsigned nBits>
655 template<
unsigned nBits>
663 template<
unsigned nBits>
667 return iterator(
this, 0);
671 template<
unsigned nBits>
675 return const_iterator(
this, 0);
679 template<
unsigned nBits>
683 return const_iterator(
this, 0);
687 template<
unsigned nBits>
691 return iterator(
this,
size_);
695 template<
unsigned nBits>
699 return const_iterator(
this,
size_);
703 template<
unsigned nBits>
707 return const_iterator(
this,
size_);
713 template<
unsigned nBits>
720 template<
unsigned nBits>
727 template<
unsigned nBits>
731 const unsigned int& val
745 unsigned int fill = val;
754 for (
unsigned int i = 1; i <
packing(); ++i)
756 fill |= (fill << nBits);
763 for (
label i=oldLen; i < newLen; ++i)
765 StorageList::operator[](i) = fill;
770 const unsigned int off = oldSize %
packing();
773 const unsigned int seg = oldSize /
packing();
774 const unsigned int mask =
maskLower(off);
776 StorageList::operator[](seg) &= mask;
777 StorageList::operator[](seg) |= ~mask & fill;
789 StorageList::operator[](seg) &=
maskLower(off);
794 else if (
size_ < oldSize)
802 for (
label i=newLen; i < oldLen; ++i)
804 StorageList::operator[](i) = 0u;
814 StorageList::operator[](seg) &=
maskLower(off);
821 template<
unsigned nBits>
825 const unsigned int& val
833 template<
unsigned nBits>
840 template<
unsigned nBits>
856 StorageList::operator[](seg) &=
maskLower(off);
862 template<
unsigned nBits>
884 template<
unsigned nBits>
891 template<
unsigned nBits>
899 template<
unsigned nBits>
907 template<
unsigned nBits>
918 template<
unsigned nBits>
925 template<
unsigned nBits>
932 template<
unsigned nBits>
939 template<
unsigned nBits>
946 template<
unsigned nBits>
956 template<
unsigned nBits>
963 template<
unsigned nBits>
967 if (i < 0 || i >=
size_)
973 return iteratorBase(
this, i).get();
978 template<
unsigned nBits>
982 if (i < 0 || i >=
size_)
988 return iteratorBase(
this, i).get();
993 template<
unsigned nBits>
997 const unsigned int val
1005 else if (i >=
size_)
1011 return iteratorBase(
this, i).set(val);
1015 template<
unsigned nBits>
1019 if (i < 0 || i >=
size_)
1025 return iteratorBase(
this, i).set(0u);
1030 template<
unsigned nBits>
1038 iteratorBase(
this, elemI).set(val);
1043 template<
unsigned nBits>
1053 const unsigned int val = iteratorBase(
this, elemI).get();
1060 template<
unsigned nBits>
1064 return iteratorBase(
this, i);
1068 template<
unsigned nBits>
1076 unsigned int fill = val;
1085 for (
unsigned int i = 1; i <
packing(); ++i)
1087 fill |= (fill << nBits);
1091 for (
label i=0; i < packLen; ++i)
1093 StorageList::operator[](i) = fill;
1103 StorageList::operator[](seg) &=
maskLower(off);
1109 for (
label i=0; i < packLen; ++i)
1111 StorageList::operator[](i) = 0u;
bool unset(const label)
Unset the entry at index I. Return true if value changed.
void reset()
Clear all bits.
unsigned int operator*() const
Return referenced value directly.
The iterator base for PackedList.
label packedLength() const
The list length when packed.
#define forAll(list, i)
Loop across all elements in list.
const_iterator cend() const
const_iterator set to beyond the end of the PackedList
unsigned int operator()() const
Return referenced value directly.
bool read(const char *, int32_t &)
List< unsigned int > & storage()
Return the underlying packed storage.
PackedList * list_
Pointer to original list.
void operator=(const const_iterator &)
Disallow assignment from const_iterator.
static unsigned int packing()
The number of entries per packed storage element.
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
void setCapacity(const label)
Alter the size of the underlying storage.
unsigned int operator*() const
Return value.
void operator=(const UList< T > &)
Assignment from UList operator. Takes linear time.
A simple container for copying or transferring objects of type <T>.
static unsigned int max_bits()
The max. number of bits that can be templated.
void reserve(const label)
Reserve allocation space for at least this size.
void setSize(const label, const unsigned int &val=0u)
Alias for resize()
unsigned int get() const
Get value as unsigned, no range-checking.
label size_
Number of nBits entries.
static unsigned int maskLower(unsigned offset)
Masking for all bits below the offset.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
static unsigned int readValue(Istream &)
Read a list entry (allows for specialization)
label key() const
Return the element index corresponding to the iterator.
void setPair(Istream &)
Read an index/value pair and set accordingly.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
The iterator class used for PackedList.
bool set(unsigned int)
Set value, returning true if changed, no range-checking.
bool writeIfSet(Ostream &) const
Write index/value for a non-zero entry.
unsigned int remove()
Remove and return the last element.
iterator begin()
Iterator set to the beginning of the PackedList.
unsigned int operator()() const
Return value.
bool empty() const
Return true if the list is empty (ie, size() is zero).
std::streamsize byteSize() const
Return the binary size in number of characters.
bool set(const label, const unsigned int val=~0u)
Set value at index I. Return true if value changed.
errorManip< error > abort(error &err)
unsigned int get(const label) const
Get value at index I.
errorManipArg< error, int > exit(error &err, const int errNo=1)
label size() const
Return the number of elements in the UList.
static unsigned int max_value()
The max. value for an entry, which simultaneously the bit-mask.
autoPtr< PackedList< nBits > > clone() const
Clone.
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
iterator end()
Iterator set to beyond the end of the PackedList.
iterator()
Construct null.
void setSize(const label)
Reset size of List.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
unsigned int operator=(const iteratorBase &)
Assign value, not position.
label capacity() const
The number of elements that can be stored before reallocating.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Xfer< T > xferMove(T &)
Construct by transferring the contents of the arg.
iteratorBase()
Construct null.
PackedList< nBits > & append(const unsigned int val)
Append a value at the end of the list.
Xfer< PackedList< nBits > > xfer()
Transfer contents to the Xfer container.
const_iterator()
Construct null.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
A dynamically allocatable list of packed unsigned integers.
void clear()
Clear the list, i.e. set size to zero.
Template-invariant bits for PackedList.
void resize(const label, const unsigned int &val=0u)
Reset addressable list size, does not shrink the allocated size.
label readLabel(Istream &is)
void clearStorage()
Clear the list and delete storage.
PackedList()
Null constructor.
void shrink()
Shrink the allocated space to what is actually used.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
const_iterator & operator++()
label size() const
Number of entries.
void transfer(PackedList< nBits > &)
Transfer the contents of the argument list into this list.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
The const_iterator for PackedList.
PackedList< nBits > & operator=(const unsigned int val)
Assignment of all entries to the given value. Takes linear time.
UList< label > labelUList
const_iterator cbegin() const
const_iterator set to the beginning of the PackedList
label index_
Element index.
void clear()
Clear the list, i.e. set addressable size to zero.
const_iterator & operator--()
const_iterator & operator=(const iteratorBase &)
Assign from iteratorBase or derived.
unsigned int operator[](const label) const
Get value at index I.