15 #ifndef __UT_PACKED_ARRAY_OF_ARRAYS_H__
16 #define __UT_PACKED_ARRAY_OF_ARRAYS_H__
35 { myOffsets.clear(); myData.clear(); }
37 {
return size() == 0; }
45 return (inclusive ?
sizeof(*
this) : 0) +
46 myOffsets.getMemoryUsage(
false) +
47 myData.getMemoryUsage(
false);
55 if (myOffsets.isEmpty())
57 for (
exint i = 0; i < len; i++)
58 myData.append(data[i]);
59 myOffsets.append(myData.entries());
77 *
this = std::move(arr);
83 myData.concat(std::move(arr.myData));
85 myOffsets.bumpCapacity(myOffsets.size() + arr.size());
86 for (
exint i = 0,
n = arr.size(); i <
n; ++i)
87 myOffsets.append(myOffsets.last() + arr.arrayLen(i));
89 arr.myOffsets.clear();
96 if (myOffsets.isEmpty())
98 exint base = myOffsets.last();
99 myOffsets.append(base+len);
100 myData.bumpSize(base+len);
101 return myData.array() + base;
108 exint base = myOffsets(idx);
110 return myData(base+idx_in_array);
117 exint base = myOffsets(idx);
118 exint len = myOffsets(idx+1)-base;
120 for (
exint i = 0; i < len; i++)
121 result(i) = myData(base+i);
130 return myData.array() + myOffsets(idx);
135 return myData.array() + myOffsets(idx);
139 return myOffsets(idx+1)-myOffsets(idx);
149 {
return UTmakeRange(arrayData(idx), arrayData(idx + 1)); }
151 {
return UTmakeRange(arrayData(idx), arrayData(idx + 1)); }
157 if (maxsize >= 0 &&
size() > maxsize)
163 myOffsets.setSize(maxsize+1);
164 myData.setSize(myOffsets(maxsize));
173 { myData.setCapacity(capacity); }
175 { myData.setCapacityIfNeeded(capacity); }
177 { myOffsets.setCapacity(capacity); }
179 { myOffsets.setCapacityIfNeeded(capacity); }
void setDataCapacity(exint capacity)
const T & operator()(exint idx, exint idx_in_array) const
From the given idxth array, return the idx_in_array element.
void truncate(exint maxsize)
Decreases, but never expands, to the given maxsize.
UT_Array< exint > & rawOffsets()
UT_IteratorRange< IterT > UTmakeRange(IterT &&b, IterT &&e)
const UT_Array< T > & rawData() const
**But if you need a result
UT_IteratorRange< const T * > arrayRange(exint idx) const
void append(const UT_PackedArrayOfArrays< T > &arr, exint idx)
void append(const T *data, exint len)
void setArrayCapacity(exint capacity)
const UT_Array< exint > & rawOffsets() const
const T * arrayData(exint idx) const
void concat(const UT_PackedArrayOfArrays< T > &arr)
Appends an array of arrays to our list.
UT_Array< T > & rawData()
All of the array data is in one contiguous block.
void setArrayCapacityIfNeeded(exint capacity)
UT_Span< const T > span(exint idx) const
void concat(UT_PackedArrayOfArrays< T > &&arr)
Moves an array of arrays to our list.
void extract(UT_Array< T > &result, exint idx) const
Extracts an array into a UT_Array.
T * appendArray(exint len)
exint size() const
Returns the number of arrays in this structure.
exint entries() const
Alias of size(). size() is preferred.
void setDataCapacityIfNeeded(exint capacity)
int64 getMemoryUsage(bool inclusive=false) const
void append(const UT_Array< T > &arr)
Adds a new array to the end of our list of arrays.
exint arrayLen(exint idx) const
UT_IteratorRange< T * > arrayRange(exint idx)