30 template<
unsigned nBits>
37 template<
unsigned nBits>
40 return (1u << nBits) - 1;
44 template<
unsigned nBits>
51 template<
unsigned nBits>
61 template<
unsigned nBits>
64 return (nElem + packing() - 1) / packing();
102 template<
unsigned nBits>
107 if (val > max_value())
110 <<
"Out-of-range value " << val <<
" for PackedList<" << nBits
111 <<
">. Maximum permitted value is " << max_value() <<
"."
119 template<
unsigned nBits>
122 is.
readBegin(
"Tuple2<label, unsigned int>");
127 is.
readEnd(
"Tuple2<label, unsigned int>");
129 if (val > max_value())
132 <<
"Out-of-range value " << val <<
" for PackedList<" << nBits
133 <<
"> at index " << ind
134 <<
". Maximum permitted value is " << max_value() <<
"."
141 is.
check(
"PackedList<nBits>::setPair(Istream&)");
145 template<
unsigned nBits>
167 template<
unsigned nBits>
176 template<
unsigned nBits>
185 template<
unsigned nBits>
189 const unsigned int val
193 StorageList(packedLength(size), 0u),
203 template<
unsigned nBits>
214 template<
unsigned nBits>
223 template<
unsigned nBits>
230 template<
unsigned nBits>
244 template<
unsigned nBits>
258 template<
unsigned nBits>
268 template<
unsigned nBits>
276 template<
unsigned nBits>
288 template<
unsigned nBits>
292 const unsigned int seg = index_ / packing();
293 const unsigned int off = index_ % packing();
295 const unsigned int& stored = list_->StorageList::operator[](seg);
296 return (stored >> (nBits * off)) & max_value();
300 template<
unsigned nBits>
304 const unsigned int seg = index_ / packing();
305 const unsigned int off = index_ % packing();
307 const unsigned int startBit = nBits * off;
308 const unsigned int mask = max_value() << startBit;
310 unsigned int& stored = list_->StorageList::operator[](seg);
311 const unsigned int prev = stored;
313 if (val >= max_value())
321 stored |= mask & (val << startBit);
324 return prev != stored;
328 template<
unsigned nBits>
335 template<
unsigned nBits>
341 return this->get() == iter.
get();
345 template<
unsigned nBits>
351 return this->get() != iter.
get();
355 template<
unsigned nBits>
361 const unsigned int val = iter.
get();
366 template<
unsigned nBits>
369 const unsigned int val
373 if (index_ >= list_->size_)
375 list_->
resize(index_ + 1);
382 template<
unsigned nBits>
384 unsigned int ()
const
387 if (index_ >= list_->size_)
396 template<
unsigned nBits>
403 template<
unsigned nBits>
410 template<
unsigned nBits>
427 template<
unsigned nBits>
444 template<
unsigned nBits>
455 template<
unsigned nBits>
466 template<
unsigned nBits>
472 iteratorBase(static_cast<const iteratorBase&>(iter))
476 template<
unsigned nBits>
482 return this->index_ == iter.
index_;
486 template<
unsigned nBits>
492 return this->index_ != iter.
index_;
496 template<
unsigned nBits>
502 return this->index_ == iter.
index_;
506 template<
unsigned nBits>
512 return this->index_ != iter.
index_;
516 template<
unsigned nBits>
522 this->list_ = iter.
list_;
523 this->index_ = iter.
index_;
527 if (this->index_ > this->list_->size_)
529 this->index_ = this->list_->size_;
534 template<
unsigned nBits>
537 const iteratorBase& iter
540 this->list_ = iter.
list_;
545 if (this->index_ > this->list_->size_)
547 this->index_ = this->list_->size_;
552 template<
unsigned nBits>
561 template<
unsigned nBits>
570 template<
unsigned nBits>
580 template<
unsigned nBits>
590 template<
unsigned nBits>
599 template<
unsigned nBits>
608 template<
unsigned nBits>
618 template<
unsigned nBits>
628 template<
unsigned nBits>
636 template<
unsigned nBits>
644 template<
unsigned nBits>
652 template<
unsigned nBits>
660 template<
unsigned nBits>
668 template<
unsigned nBits>
676 template<
unsigned nBits>
684 template<
unsigned nBits>
694 template<
unsigned nBits>
701 template<
unsigned nBits>
708 template<
unsigned nBits>
712 const unsigned int& val
717 const label oldSize = size_;
726 unsigned int fill = val;
728 if (val >= max_value())
731 fill = maskLower(packing());
735 for (
unsigned int i = 1; i < packing(); ++i)
737 fill |= (fill << nBits);
742 const label oldLen = packedLength(oldSize);
743 const label newLen = packedLength(size_);
744 for (
label i=oldLen; i < newLen; ++i)
746 StorageList::operator[](i) = fill;
751 const unsigned int off = oldSize % packing();
754 const unsigned int seg = oldSize / packing();
755 const unsigned int mask = maskLower(off);
757 StorageList::operator[](seg) &= mask;
758 StorageList::operator[](seg) |= ~mask & fill;
765 const unsigned int off = size_ % packing();
768 const unsigned int seg = size_ / packing();
770 StorageList::operator[](seg) &= maskLower(off);
775 else if (size_ < oldSize)
781 const label oldLen = packedLength(oldSize);
782 const label newLen = packedLength(size_);
783 for (
label i=newLen; i < oldLen; ++i)
785 StorageList::operator[](i) = 0u;
790 const unsigned int off = size_ % packing();
793 const unsigned int seg = size_ / packing();
795 StorageList::operator[](seg) &= maskLower(off);
802 template<
unsigned nBits>
806 const unsigned int& val
814 template<
unsigned nBits>
817 return packing() * StorageList::size();
821 template<
unsigned nBits>
832 const unsigned int off = size_ % packing();
835 const unsigned int seg = size_ / packing();
837 StorageList::operator[](seg) &= maskLower(off);
843 template<
unsigned nBits>
846 const label len = packedLength(nElem);
849 if (len > StorageList::size())
857 StorageList::size()*2
865 template<
unsigned nBits>
868 StorageList::operator=(0u);
872 template<
unsigned nBits>
880 template<
unsigned nBits>
888 template<
unsigned nBits>
892 const label len = packedLength();
893 if (len < StorageList::size())
899 template<
unsigned nBits>
906 template<
unsigned nBits>
913 template<
unsigned nBits>
916 return packedLength(size_);
920 template<
unsigned nBits>
927 template<
unsigned nBits>
933 StorageList::transfer(lst);
937 template<
unsigned nBits>
941 if (i < 0 || i >= size_)
952 template<
unsigned nBits>
956 if (i < 0 || i >= size_)
967 template<
unsigned nBits>
971 const unsigned int val
989 template<
unsigned nBits>
993 if (i < 0 || i >= size_)
1004 template<
unsigned nBits>
1008 const label elemI = size_;
1017 template<
unsigned nBits>
1026 label elemI = size_ - 1;
1034 template<
unsigned nBits>
1042 template<
unsigned nBits>
1045 const label packLen = packedLength();
1049 unsigned int fill = val;
1051 if (val >= max_value())
1054 fill = maskLower(packing());
1058 for (
unsigned int i = 1; i < packing(); ++i)
1060 fill |= (fill << nBits);
1064 for (
label i=0; i < packLen; ++i)
1066 StorageList::operator[](i) = fill;
1071 const unsigned int off = size_ % packing();
1074 const unsigned int seg = size_ / packing();
1076 StorageList::operator[](seg) &= maskLower(off);
1082 for (
label i=0; i < packLen; ++i)
1084 StorageList::operator[](i) = 0u;
#define forAll(list, i)
Loop across all elements in list.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Istream & readEnd(const char *funcName)
Istream & readBegin(const char *funcName)
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
The const_iterator for PackedList.
const_iterator & operator--()
const_iterator & operator++()
const_iterator()
Construct null.
The iterator base for PackedList.
label key() const
Return the element index corresponding to the iterator.
bool set(unsigned int) const
Set value, returning true if changed, no range-checking.
iteratorBase()
Construct null.
label index_
Element index.
unsigned int get() const
Get value as unsigned, no range-checking.
bool writeIfSet(Ostream &) const
Write index/value for a non-zero entry.
PackedList * list_
Pointer to original list.
The iterator class used for PackedList.
iterator()
Construct null.
const iteratorBase & operator()() const
Return iteratorBase for assigning values.
const iteratorBase & operator*() const
Return iteratorBase for assigning values.
A dynamically allocatable list of packed unsigned integers.
static unsigned int max_value()
The max. value for an entry, which simultaneously the bit-mask.
autoPtr< PackedList< nBits > > clone() const
Clone.
void shrink()
Shrink the allocated space to what is actually used.
List< unsigned int > & storage()
Return the underlying packed storage.
bool set(const label, const unsigned int val=~0u)
Set value at index I. Return true if value changed.
static unsigned int maskLower(unsigned offset)
Masking for all bits below the offset.
void resize(const label, const unsigned int &val=0u)
Reset addressable list size, does not shrink the allocated size.
void setSize(const label, const unsigned int &val=0u)
Alias for resize()
void setCapacity(const label)
Alter the size of the underlying storage.
label size() const
Number of entries.
void transfer(PackedList< nBits > &)
Transfer the contents of the argument list into this list.
label capacity() const
The number of elements that can be stored before reallocating.
label packedLength() const
The list length when packed.
void setPair(Istream &)
Read an index/value pair and set accordingly.
iterator end()
Iterator set to beyond the end of the PackedList.
bool empty() const
Return true if the list is empty (ie, size() is zero).
static unsigned int packing()
The number of entries per packed storage element.
const_iterator cend() const
const_iterator set to beyond the end of the PackedList
iterator begin()
Iterator set to the beginning of the PackedList.
void reserve(const label)
Reserve allocation space for at least this size.
unsigned int get(const label) const
Get value at index I.
void clearStorage()
Clear the list and delete storage.
PackedList()
Null constructor.
static unsigned int max_bits()
The max. number of bits that can be templated.
const_iterator cbegin() const
const_iterator set to the beginning of the PackedList
bool unset(const label)
Unset the entry at index I. Return true if value changed.
void operator=(const unsigned int val)
Assignment of all entries to the given value. Takes linear time.
std::streamsize byteSize() const
Return the binary size in number of characters.
static unsigned int readValue(Istream &)
Read a list entry (allows for specialisation)
PackedList< nBits > & append(const unsigned int val)
Append a value at the end of the list.
void clear()
Clear the list, i.e. set addressable size to zero.
unsigned int operator[](const label) const
Get value at index I.
void reset()
Clear all bits.
unsigned int remove()
Remove and return the last element.
A List with indirect addressing.
T * iterator
Random access iterator for traversing UList.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
errorManipArg< error, int > exit(error &err, const int errNo=1)
bool read(const char *, int32_t &)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
errorManip< error > abort(error &err)
label readLabel(Istream &is)
void offset(label &lst, const label o)
dimensioned< Type > max(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
points setSize(newPointi)
triSurfaceToAgglom resize(surfacesMesh.size())
Template-invariant bits for PackedList.