37 const label prevOffset,
48 <<
"Overflow : sum of sizes exceeds labelMax (" 49 <<
labelMax <<
") after index " << idx;
51 if (prevOffset >= 0 &&
count >= 0)
54 <<
" while trying to add (" <<
count 55 <<
") to offset (" << prevOffset <<
")";
60 <<
"Please recompile with larger datatype for label." <<
nl 66 template<
class ListListType>
69 const ListListType& lists,
70 const bool checkOverflow
75 auto& newOffsets = compact.offsets_;
76 auto& newValues = compact.values_;
79 const label len = lists.size();
85 for (label i = 0; i < len; ++i)
87 const label
count = lists[i].size();
89 newOffsets[i] = total;
92 if (checkOverflow && total < newOffsets[i])
94 reportOverflowAndExit(i, newOffsets[i],
count);
97 newOffsets[len] = total;
103 newValues.resize(total);
105 auto iter = newValues.begin();
110 for (
const auto& list : lists)
112 const label sublen = list.
size();
114 for (label i = 0; i < sublen; (void)++i, (
void)++iter)
126 template<
class SubListType>
130 const bool checkOverflow
142 template<
class SubListType,
class Addr>
146 const bool checkOverflow
163 const bool checkOverflow
166 const label len = listSizes.
size();
171 offsets_.resize(len+1);
173 for (label i = 0; i < len; ++i)
175 const label
count = listSizes[i];
180 if (checkOverflow && total < offsets_[i])
182 reportOverflowAndExit(i, offsets_[i],
count);
186 offsets_[len] = total;
202 const label total = resize_offsets(listSizes,
true);
204 const label total = resize_offsets(listSizes,
false);
206 values_.resize(total);
218 const label total = resize_offsets(listSizes,
true);
220 const label total = resize_offsets(listSizes,
false);
222 values_.resize(total, val);
231 const label len = (offsets_.size() - 1);
240 for (label i=0; i < len; ++i)
244 const label
count = (offsets_[i+1] - offsets_[i]);
256 if constexpr (!is_contiguous_v<T>)
259 <<
"Invalid for non-contiguous data types" 262 return this->size_bytes();
269 return labelRange(offsets_[i], offsets_[i+1] - offsets_[i]);
279 const label len = (offsets_.size() - 1);
288 for (label i=0; i < len; ++i)
290 values[i].reset(offsets_[i], (offsets_[i+1] - offsets_[i]));
301 const label total = resize_offsets(listSizes,
true);
303 const label total = resize_offsets(listSizes,
false);
305 values_.resize(total);
313 const label total = resize_offsets(listSizes,
true);
315 const label total = resize_offsets(listSizes,
false);
317 values_.resize_nocopy(total);
324 if (rowi >= 0 && rowi+1 < offsets_.size() && len >= 0)
326 const label
delta = (len - (offsets_[rowi+1] - offsets_[rowi]));
331 for (label i = rowi+1; i < offsets_.size(); ++i)
333 offsets_[i] +=
delta;
345 const label len = (offsets_.size() - 1);
354 for (label i=0; i < len; ++i)
356 values[i] = offsets_[i+1] - offsets_[i];
374 offsets_.swap(other.offsets_);
375 values_.swap(other.values_);
390 offsets_.transfer(list.offsets_);
391 values_.transfer(list.values_);
396 template<
class SubListType,
class OutputIter>
404 if (
pos >= 0 && pos < this->size())
409 if (len > 0) len +=
pos;
410 if (len < 0 || len > this->size())
415 for (label i =
pos; i < len; ++i)
417 *d_iter = SubListType(this->localList(i));
427 template<
class SubListType,
class OutputIter>
434 return this->copy_unpack<SubListType>(d_iter,
range.start(),
range.size());
439 template<
class SubListType,
class OutputIter>
446 for (label i : indices)
448 *d_iter = SubListType(this->localList(i));
462 template<
class SubListType>
468 this->copy_unpack<SubListType>(lists.
begin());
475 template<
class SubListType>
481 this->copy_unpack<SubListType>(lists.begin(),
range.start(),
range.size());
488 template<
class SubListType>
494 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.