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>
540 this->list_ = iter.
list_;
541 this->index_ = iter.
index_;
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>
692 template<
unsigned nBits>
700 template<
unsigned nBits>
710 template<
unsigned nBits>
717 template<
unsigned nBits>
724 template<
unsigned nBits>
728 const unsigned int& val
733 const label oldSize = size_;
742 unsigned int fill = val;
744 if (val >= max_value())
747 fill = maskLower(packing());
751 for (
unsigned int i = 1; i < packing(); ++i)
753 fill |= (fill << nBits);
758 const label oldLen = packedLength(oldSize);
759 const label newLen = packedLength(size_);
760 for (
label i=oldLen; i < newLen; ++i)
762 StorageList::operator[](i) = fill;
767 const unsigned int off = oldSize % packing();
770 const unsigned int seg = oldSize / packing();
771 const unsigned int mask = maskLower(off);
773 StorageList::operator[](seg) &= mask;
774 StorageList::operator[](seg) |= ~mask & fill;
781 const unsigned int off = size_ % packing();
784 const unsigned int seg = size_ / packing();
786 StorageList::operator[](seg) &= maskLower(off);
791 else if (size_ < oldSize)
797 const label oldLen = packedLength(oldSize);
798 const label newLen = packedLength(size_);
799 for (
label i=newLen; i < oldLen; ++i)
801 StorageList::operator[](i) = 0u;
806 const unsigned int off = size_ % packing();
809 const unsigned int seg = size_ / packing();
811 StorageList::operator[](seg) &= maskLower(off);
818 template<
unsigned nBits>
822 const unsigned int& val
830 template<
unsigned nBits>
833 return packing() * StorageList::size();
837 template<
unsigned nBits>
848 const unsigned int off = size_ % packing();
851 const unsigned int seg = size_ / packing();
853 StorageList::operator[](seg) &= maskLower(off);
859 template<
unsigned nBits>
862 const label len = packedLength(nElem);
865 if (len > StorageList::size())
873 StorageList::size()*2
881 template<
unsigned nBits>
884 StorageList::operator=(0u);
888 template<
unsigned nBits>
896 template<
unsigned nBits>
904 template<
unsigned nBits>
908 const label len = packedLength();
909 if (len < StorageList::size())
915 template<
unsigned nBits>
922 template<
unsigned nBits>
929 template<
unsigned nBits>
932 return packedLength(size_);
936 template<
unsigned nBits>
943 template<
unsigned nBits>
949 StorageList::transfer(lst);
953 template<
unsigned nBits>
957 if (i < 0 || i >= size_)
968 template<
unsigned nBits>
972 if (i < 0 || i >= size_)
983 template<
unsigned nBits>
987 const unsigned int val
1005 template<
unsigned nBits>
1009 if (i < 0 || i >= size_)
1020 template<
unsigned nBits>
1024 const label elemI = size_;
1033 template<
unsigned nBits>
1042 label elemI = size_ - 1;
1050 template<
unsigned nBits>
1058 template<
unsigned nBits>
1061 const label packLen = packedLength();
1065 unsigned int fill = val;
1067 if (val >= max_value())
1070 fill = maskLower(packing());
1074 for (
unsigned int i = 1; i < packing(); ++i)
1076 fill |= (fill << nBits);
1080 for (
label i=0; i < packLen; ++i)
1082 StorageList::operator[](i) = fill;
1087 const unsigned int off = size_ % packing();
1090 const unsigned int seg = size_ / packing();
1092 StorageList::operator[](seg) &= maskLower(off);
1098 for (
label i=0; i < packLen; ++i)
1100 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--()
unsigned int operator()() const
Return referenced value directly.
const_iterator & operator++()
const_iterator()
Construct null.
unsigned int operator*() const
Return referenced value directly.
The iterator base for PackedList.
label key() const
Return the element index corresponding to the iterator.
bool set(unsigned int)
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.
unsigned int operator()() const
Return value.
iterator()
Construct null.
unsigned int operator*() const
Return value.
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)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
label readLabel(Istream &is)
void offset(label &lst, const label o)
points setSize(newPointi)
triSurfaceToAgglom resize(surfacesMesh.size())
Template-invariant bits for PackedList.