34void Foam::CompactListList<T>::reportOverflowAndExit
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
66template<
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)
126template<
class SubListType>
130 const bool checkOverflow
142template<
class SubListType,
class Addr>
146 const bool checkOverflow
160Foam::label Foam::CompactListList<T>::resize_offsets
162 const labelUList& listSizes,
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);
229Foam::label Foam::CompactListList<T>::maxNonLocalSize(
const label rowi)
const
231 const label len = (offsets_.size() - 1);
240 for (label i=0; i < len; ++i)
244 const label
count = (offsets_[i+1] - offsets_[i]);
245 maxLen =
max(maxLen, count);
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];
366 CompactListList<T>& other
374 offsets_.swap(other.offsets_);
375 values_.swap(other.values_);
390 offsets_.transfer(list.offsets_);
391 values_.transfer(list.values_);
396template<
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));
427template<
class SubListType,
class OutputIter>
439template<
class SubListType,
class OutputIter>
446 for (label i : indices)
448 *d_iter = SubListType(this->localList(i));
462template<
class SubListType>
475template<
class SubListType>
481 this->copy_unpack<SubListType>(lists.
begin(),
range.start(),
range.size());
488template<
class SubListType>
494 this->copy_unpack<SubListType>(lists.
begin(), indices);
A packed storage of objects of type <T> using an offset table for access.
List< SubListType > unpack() const
Return non-compact list of lists.
void resize_nocopy(const label mRows, const label nVals)
Redimension without preserving existing content.
const List< T > & values() const noexcept
Return the packed values.
List< labelRange > ranges() const
Return start/size ranges for all sub-lists.
labelRange range(const label i) const
Return start/size range for given sub-list.
static CompactListList< T > pack(const UList< SubListType > &lists, const bool checkOverflow=false)
Construct by packing together the list of lists.
void transfer(CompactListList< T > &list)
Transfer contents into this and annul the argument.
label size() const noexcept
The primary size (the number of rows/sublists).
std::streamsize byteSize() const
Number of contiguous bytes for the values data, runtime FatalError if type is not contiguous.
const SubList< T > localList(const label i) const
Return const access to sub-list (no subscript checking).
void setLocalSize(const label rowi, const label len)
Alter local addressing size for given row, does not change content.
void resize(const label mRows)
Reset size of CompactListList.
labelList localSizes() const
The local row sizes.
void swap(CompactListList< T > &other)
Swap contents.
std::streamsize size_bytes() const noexcept
Number of contiguous bytes for the values data, no runtime check that the type is actually contiguous...
CompactListList() noexcept=default
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()...
Base for lists with indirect addressing, templated on the list contents type and the addressing type....
label size() const noexcept
The number of elements in the list.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
iterator begin() noexcept
Return an iterator to begin traversing the UList.
void size(const label n)
Older name for setAddressableSize.
A range or interval of labels defined by a start and a size.
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
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)
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
List< label > labelList
A List of labels.
errorManip< error > abort(error &err)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
constexpr bool is_contiguous_v
The is_contiguous value of Type (after stripping of qualifiers).
errorManipArg< error, int > exit(error &err, const int errNo=1)
UList< label > labelUList
A UList of labels.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
constexpr char nl
The newline '\n' character (0x0a).