11 #ifndef __UT_RLEArray__
12 #define __UT_RLEArray__
42 , myStartIndex(start_index)
55 return myRepeat >= 0 ? myRepeat : myArray.size();
61 return myRepeat >= 0 ? mySingle : myArray[idx];
82 UT_ASSERT(myRepeat > 0 && myArray.size() == 0);
83 myArray.appendMultiple(mySingle, myRepeat);
93 for (
exint i = myArray.size(); i-- > 0; )
95 if (myArray[i] != item)
96 return (myArray.size() - 1) - i;
98 return myArray.size();
103 myArray.setSize(myArray.size() -
n);
114 return myArray.getMemoryUsage() +
sizeof(
exint) +
sizeof(
T);
141 for (
auto &&item : arr)
160 for (
auto &&
run : myRuns)
168 for (
auto &&
run : myRuns)
170 return mem + myRuns.getMemoryUsage() +
sizeof(
exint);
176 return myRuns.size() == 1 && myRuns[0].isRun();
180 return myRuns[0].arrayItem(0);
187 auto &&it = std::lower_bound(myRuns.begin(), myRuns.end(), idx,
194 return run.endIndex() <=
value;
196 return (*it)[idx - (*it).startIndex()];
205 for (
exint i = 0; i <
n; ++i)
210 && myRuns.last().isRun()
211 && item == myRuns.last().arrayItem(0))
213 myRuns.last().appendRun(n);
231 Run &
last = myRuns.last();
234 if (item == last.arrayItem(0))
238 if (last.runSize() > 2)
246 last.convertToSequence(item);
252 exint n = last.matchesAtEnd(item);
255 last.removeItemsFromEnd(n);
257 myRuns.last().adjustStartOffset(n);
261 last.appendSequence(item);
286 return myArray->run(myRunIndex)[myRunOffset];
292 return myArray == i.myArray
293 && myRunIndex == i.myRunIndex
294 && myRunOffset == i.myRunOffset;
298 return !(*
this == i);
302 return myRunIndex >= myArray->numRuns();
316 if (myRunOffset >= myArray->run(myRunIndex).size())
326 , myRunIndex(end ? array.
numRuns() : 0)
343 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
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 void adjustStartOffset(exint n)
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.