38 const label prevOffset,
49 <<
"Overflow : sum of sizes exceeds labelMax (" 50 <<
labelMax <<
") after index " << idx;
52 if (prevOffset >= 0 &&
count >= 0)
55 <<
" while trying to add (" <<
count 56 <<
") to offset (" << prevOffset <<
")";
61 <<
"Please recompile with larger datatype for label." <<
nl 67 template<
class ListListType>
70 const ListListType& lists,
71 const bool checkOverflow
76 auto& newOffsets = compact.offsets_;
77 auto& newValues = compact.values_;
80 const label len = lists.size();
86 for (label i = 0; i < len; ++i)
88 const label
count = lists[i].size();
90 newOffsets[i] = total;
93 if (checkOverflow && total < newOffsets[i])
95 reportOverflowAndExit(i, newOffsets[i],
count);
98 newOffsets[len] = total;
104 newValues.resize(total);
106 auto iter = newValues.begin();
111 for (
const auto& list : lists)
113 const label sublen = list.
size();
115 for (label i = 0; i < sublen; (void)++i, (
void)++iter)
127 template<
class SubListType>
131 const bool checkOverflow
143 template<
class SubListType,
class Addr>
147 const bool checkOverflow
164 const bool checkOverflow
167 const label len = listSizes.
size();
172 offsets_.resize(len+1);
174 for (label i = 0; i < len; ++i)
176 const label
count = listSizes[i];
181 if (checkOverflow && total < offsets_[i])
183 reportOverflowAndExit(i, offsets_[i],
count);
187 offsets_[len] = total;
203 const label total = resize_offsets(listSizes,
true);
205 const label total = resize_offsets(listSizes,
false);
207 values_.resize(total);
219 const label total = resize_offsets(listSizes,
true);
221 const label total = resize_offsets(listSizes,
false);
223 values_.resize(total, val);
232 const label len = (offsets_.size() - 1);
241 for (label i=0; i < len; ++i)
245 const label
count = (offsets_[i+1] - offsets_[i]);
257 if (!is_contiguous<T>::value)
260 <<
"Invalid for non-contiguous data types" 263 return this->size_bytes();
270 return labelRange(offsets_[i], offsets_[i+1] - offsets_[i]);
280 const label len = (offsets_.size() - 1);
289 for (label i=0; i < len; ++i)
291 values[i].reset(offsets_[i], (offsets_[i+1] - offsets_[i]));
302 const label total = resize_offsets(listSizes,
true);
304 const label total = resize_offsets(listSizes,
false);
306 values_.resize(total);
314 const label total = resize_offsets(listSizes,
true);
316 const label total = resize_offsets(listSizes,
false);
318 values_.resize_nocopy(total);
325 if (rowi >= 0 && rowi+1 < offsets_.size() && len >= 0)
327 const label
delta = (len - (offsets_[rowi+1] - offsets_[rowi]));
332 for (label i = rowi+1; i < offsets_.size(); ++i)
334 offsets_[i] +=
delta;
346 const label len = (offsets_.size() - 1);
355 for (label i=0; i < len; ++i)
357 values[i] = offsets_[i+1] - offsets_[i];
375 offsets_.swap(other.offsets_);
376 values_.swap(other.values_);
391 offsets_.transfer(list.offsets_);
392 values_.transfer(list.values_);
397 template<
class SubListType,
class OutputIter>
405 if (
pos >= 0 && pos < this->size())
410 if (len > 0) len +=
pos;
411 if (len < 0 || len > this->size())
416 for (label i =
pos; i < len; ++i)
418 *d_iter = SubListType(this->localList(i));
428 template<
class SubListType,
class OutputIter>
435 return this->copy_unpack<SubListType>(d_iter,
range.start(),
range.size());
440 template<
class SubListType,
class OutputIter>
447 for (label i : indices)
449 *d_iter = SubListType(this->localList(i));
463 template<
class SubListType>
469 this->copy_unpack<SubListType>(lists.
begin());
476 template<
class SubListType>
482 this->copy_unpack<SubListType>(lists.begin(),
range.start(),
range.size());
489 template<
class SubListType>
495 this->copy_unpack<SubListType>(lists.begin(), indices);
void size(const label n)
Older name for setAddressableSize.
errorManipArg< error, int > exit(error &err, const int errNo=1)
label size() const noexcept
The primary size (the number of rows/sublists)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
A range or interval of labels defined by a start and a size.
constexpr char nl
The newline '\n' character (0x0a)
void swap(CompactListList< T > &other)
Swap contents.
static CompactListList< T > pack(const UList< SubListType > &lists, const bool checkOverflow=false)
Construct by packing together the list of lists.
Base for lists with indirect addressing, templated on the list contents type and the addressing type...
UList< label > labelUList
A UList of labels.
void transfer(CompactListList< T > &list)
Transfer contents into this and annul the argument.
void setLocalSize(const label rowi, const label len)
Alter local addressing size for given row, does not change content.
List< labelRange > ranges() const
Return start/size ranges for all sub-lists.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
dimensionedScalar pos(const dimensionedScalar &ds)
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
List< SubListType > unpack() const
Return non-compact list of lists.
labelRange range(const label i) const
Return start/size range for given sub-list.
CompactListList() noexcept=default
Default construct.
void resize(const label mRows)
Reset size of CompactListList.
errorManip< error > abort(error &err)
iterator begin() noexcept
Return an iterator to begin traversing the UList.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
std::streamsize byteSize() const
Number of contiguous bytes for the values data, runtime FatalError if type is not contiguous...
A packed storage of objects of type <T> using an offset table for access.
OutputIter copy_unpack(OutputIter d_iter, const label pos=0, label len=-1) const
Unpack sub-list copies in the range defined by pos and len with bounding behaviour like List::slice()...
labelList localSizes() const
The local row sizes.
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
void resize_nocopy(const label mRows, const label nVals)
Redimension without preserving existing content.
List< label > labelList
A List of labels.