8 #ifndef __SIM_PtrArraySorted_h__
9 #define __SIM_PtrArraySorted_h__
16 comparePointers(
void *
const*
a,
void *
const*
b)
18 ptrdiff_t pa = ptrdiff_t(*a), pb = ptrdiff_t(*b);
19 if (pa < pb)
return -1;
20 if (pa > pb)
return 1;
38 : myComparator(comparator)
49 { myComparator =
cmp; myArray.sort(myComparator); }
51 { myArray.sort(myComparator); }
55 return myArray.size();
59 myArray.setSize(newsize);
63 myArray.setCapacity(newcapacity);
68 { setSize(newnumentries); }
70 { setCapacity(newsize); }
73 {
return myArray(index); }
75 {
return myArray.last(); }
77 {
return myArray.sortedFind(ptr, myComparator); }
84 if( entries() != cmp.
entries() )
88 for( idx = 0; idx < num; idx++ )
91 cmpptr = cmp.myArray(idx);
92 diff = myComparator(&ptr, &cmpptr);
104 int idx, cmpidx, num, numcmp, diff;
108 for( idx = 0, cmpidx = 0;
109 idx < num && cmpidx < numcmp; )
112 cmpptr = cmp.myArray(cmpidx);
113 diff = myComparator(&ptr, &cmpptr);
134 int idx, cmpidx, num, numcmp, diff;
138 for( idx = 0, cmpidx = 0;
139 idx < num && cmpidx < numcmp; )
142 cmpptr = cmp.myArray(cmpidx);
143 diff = myComparator(&ptr, &cmpptr);
160 return (cmpidx >= numcmp) ?
true :
false;
164 { myArray.removeIndex(
index); }
166 {
int pos =
find(
ptr);
if( pos >= 0 )
remove(pos); }
167 void remove(
const SIM_PtrArraySorted &
src)
170 int idx, srcidx, diff, numsrc;
171 bool removed =
false;
173 numsrc =
src.entries();
174 for( idx = 0, srcidx = 0;
175 srcidx < numsrc && idx < entries(); )
177 destptr = myArray(idx);
178 srcptr =
src.myArray(srcidx);
179 diff = myComparator(&destptr, &srcptr);
197 myArray.removeZeros();
202 int idx, srcidx, diff, numsrc;
203 bool removed =
false;
206 for( idx = 0, srcidx = 0; idx < entries(); )
208 if( srcidx < numsrc )
210 destptr = myArray(idx);
211 srcptr = src.myArray(srcidx);
212 diff = myComparator(&destptr, &srcptr);
231 myArray.removeZeros();
242 uniqueSortedInsert(ptr, myComparator);
246 myComparator = src.myComparator;
247 myArray = src.myArray;
250 SIM_PtrArraySorted &duplicates)
257 for( idx = 1; idx < entries(); idx++ )
259 lastptr = myArray(idx-1);
260 nextptr = myArray(idx);
261 if( myComparator(&lastptr, &nextptr) == 0 )
263 duplicates.
add(lastptr);
268 myArray.removeZeros();
281 T srcptr = src.myArray(0);
282 for(--i; i >= 0 && myComparator(&myArray(i), &srcptr) > 0; --i)
284 myArray(--idx) = myArray(i);
296 int cmp = myComparator(&myArray(idx), &src.myArray(src_idx));
298 myArray(i++) = myArray(idx++);
300 myArray(i++) = src.myArray(src_idx++);
303 while(src_idx < n_src)
304 myArray(i++) = src.myArray(src_idx++);
310 for(
int i = merge_start; i <
n; ++i)
312 if(myComparator(&myArray(i), &myArray(i - 1)))
313 myArray(merge_start++) = myArray(i);
315 entries(merge_start);
318 bool (*selectfunc)(T))
321 int idx, srcidx, diff, numsrc;
323 numsrc = src.entries();
324 for( idx = 0, srcidx = 0; srcidx < numsrc; )
328 if( selectfunc(src.myArray(srcidx)) )
330 if( idx < entries() )
332 destptr = myArray(idx);
333 srcptr = src.myArray(srcidx);
334 diff = myComparator(&destptr, &srcptr);
345 myArray.insert(
src(srcidx), idx);
358 { myArray.append(ptr); }
void merge(const SIM_PtrArraySorted &src)
#define SYS_DEPRECATED(__V__)
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
#define SYS_DEPRECATED_PUSH_DISABLE()
#define SYS_DEPRECATED_POP_DISABLE()
GLboolean GLboolean GLboolean GLboolean a
void setComparator(typename UT_ValArray< T >::Comparator cmp)
IMATH_HOSTDEVICE constexpr int cmp(T a, T b) IMATH_NOEXCEPT
SIM_PtrArraySorted(const SIM_PtrArraySorted &src)
void setUnsorted(const UT_ValArray< T > &src, SIM_PtrArraySorted &duplicates)
void entries(int newnumentries)
void set(const SIM_PtrArraySorted &src)
bool operator==(const SIM_PtrArraySorted &cmp) const
UT_ValArray< T > & getRawArray()
void setCapacity(exint newcapacity)
void setSize(exint newsize)
GLboolean GLboolean GLboolean b
bool containsAny(const SIM_PtrArraySorted &cmp) const
ImageBuf OIIO_API resize(const ImageBuf &src, string_view filtername="", float filterwidth=0.0f, ROI roi={}, int nthreads=0)
SIM_PtrArraySorted & operator=(const SIM_PtrArraySorted &src)
SIM_PtrArraySorted(typename UT_ValArray< T >::Comparator comparator)
void keepOnly(const SIM_PtrArraySorted &src)
T operator()(int index) const
void sort(I begin, I end, const Pred &pred)
bool containsFully(const SIM_PtrArraySorted &cmp) const
virtual ~SIM_PtrArraySorted()
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool
const UT_ValArray< T > & getRawArray() const