11 #ifndef __UT_RLEArray__
12 #define __UT_RLEArray__
43 , myStartIndex(start_index)
56 return myRepeat >= 0 ? myRepeat : myArray.size();
62 return myRepeat >= 0 ? mySingle : myArray[idx];
83 UT_ASSERT(myRepeat > 0 && myArray.size() == 0);
84 myArray.appendMultiple(mySingle, myRepeat);
94 for (
exint i = myArray.size(); i-- > 0; )
96 if (myArray[i] != item)
97 return (myArray.size() - 1) - i;
99 return myArray.size();
104 myArray.setSize(myArray.size() -
n);
115 return myArray.getMemoryUsage() +
sizeof(
exint) +
sizeof(
T);
142 for (
auto &&item : arr)
161 for (
auto &&
run : myRuns)
169 for (
auto &&
run : myRuns)
171 return mem + myRuns.getMemoryUsage() +
sizeof(
exint);
177 return myRuns.size() == 1 && myRuns[0].isRun();
181 return myRuns[0].arrayItem(0);
188 auto &&it = std::lower_bound(myRuns.begin(), myRuns.end(), idx,
195 return run.endIndex() <=
value;
197 return (*it)[idx - (*it).startIndex()];
206 for (
exint i = 0; i <
n; ++i)
211 && myRuns.last().isRun()
212 && item == myRuns.last().arrayItem(0))
214 myRuns.last().appendRun(n);
233 myRuns = std::move(
src.myRuns);
240 for (
auto &&
run :
src.myRuns)
243 mySize +=
src.mySize;
247 const bool merge_runs = myRuns.last().isRun() &&
src.myRuns[0].isRun()
248 && myRuns.last().arrayItem(0)
249 ==
src.myRuns[0].arrayItem(0);
252 myRuns.last().appendRun(
src.myRuns[0].runSize());
254 myRuns.bumpCapacity(myRuns.size() +
src.myRuns.size() - 1);
255 for (
exint i = 1,
n =
src.myRuns.size(); i <
n; ++i)
256 myRuns.append(std::move(
src.myRuns[i]));
262 myRuns.concat(std::move(
src.myRuns));
275 Run &
last = myRuns.last();
278 if (item == last.arrayItem(0))
282 if (last.runSize() > 2)
290 last.convertToSequence(item);
296 exint n = last.matchesAtEnd(item);
299 last.removeItemsFromEnd(n);
301 myRuns.last().shiftStartIndex(-n);
305 last.appendSequence(item);
330 return myArray->run(myRunIndex)[myRunOffset];
336 return myArray == i.myArray
337 && myRunIndex == i.myRunIndex
338 && myRunOffset == i.myRunOffset;
342 return !(*
this == i);
346 return myRunIndex >= myArray->numRuns();
360 if (myRunOffset >= myArray->run(myRunIndex).size())
370 , myRunIndex(end ? array.
numRuns() : 0)
387 myRuns.emplace_back(item, size, mySize);
SYS_FORCE_INLINE exint numRuns() const
SYS_FORCE_INLINE void appendRun(exint num=1)
SYS_FORCE_INLINE bool isEmpty() const
GLsizei const GLfloat * value
std::ptrdiff_t difference_type
SYS_FORCE_INLINE void concat(UT_RLEArray< T > &&src)
Move and concatenate another UT_RLEArray at the end.
const T & operator*() const
SYS_FORCE_INLINE exint matchesAtEnd(const T &item) const
SYS_FORCE_INLINE void append(const T &item)
Class which writes ASCII or binary JSON streams.
SYS_FORCE_INLINE const Run & run(exint i) const
SYS_FORCE_INLINE const T & uniformItem() const
bool operator==(const iterator &i) const
UT_RLEArray(const UT_Array< T > &arr)
SYS_FORCE_INLINE void appendRun(const T &item, exint n)
SYS_FORCE_INLINE bool isUniform() const
SYS_FORCE_INLINE exint size() const
SYS_FORCE_INLINE void clear()
SYS_FORCE_INLINE void appendSequence(const T &item)
UT_RLEArray(const T *data, exint size)
SYS_FORCE_INLINE bool isEmpty() const
std::forward_iterator_tag iterator_category
SYS_FORCE_INLINE exint size() const
SYS_FORCE_INLINE exint getMemoryUsage() const
SYS_FORCE_INLINE iterator begin() const
SYS_FORCE_INLINE const T & operator[](exint idx) const
SYS_FORCE_INLINE void convertToSequence(const T &item)
SYS_FORCE_INLINE iterator end() const
SYS_FORCE_INLINE exint getMemoryUsage() const
std::string OIIO_UTIL_API repeat(string_view str, int n)
Repeat a string formed by concatenating str n times.
__hostdev__ uint64_t last(uint32_t i) const
SYS_FORCE_INLINE void removeItemsFromEnd(exint n)
SYS_FORCE_INLINE exint startIndex() const
SYS_FORCE_INLINE const T & arrayItem(exint idx) const
bool operator!=(const iterator &i) const
SYS_FORCE_INLINE exint countSize() const
SYS_FORCE_INLINE exint endIndex() const
SYS_FORCE_INLINE bool isRun() const
SYS_FORCE_INLINE exint runSize() const
Run(const T &item, exint repeat, exint start_index)
SYS_FORCE_INLINE const T & findItem(exint idx) const
Note that finding an item is O(log(N)) - where N is the number of runs.
SYS_FORCE_INLINE void shiftStartIndex(exint n)