12 #ifndef __UT_SparseArrayImpl__
13 #define __UT_SparseArrayImpl__
15 #ifndef __UT_SparseArray_h__
16 #error Do not include this file directly. Include UT_SparesArray.h instead.
37 for (i = myArray.entries()-1; i >= 0; i--)
39 if (myArray(i)->myIndex ==
index)
41 myArray(i)->myData =
data;
44 if (myArray(i)->myIndex < index)
break;
46 if (i == (
int)(myArray.entries()-1))
47 myArray.append(
new SparseEntry(index, data));
51 myArray.insert(
new SparseEntry(index, data), i);
60 if ((iidx =
find(index)) >= 0)
63 myArray.removeIndex(iidx);
71 for (
exint i = 0; i < myArray.entries(); ++i)
73 myArray.setCapacity(0);
81 if (raw_index >= 0 && raw_index < myArray.entries())
83 index = myArray(raw_index)->myIndex;
84 return myArray(raw_index)->myData;
94 return ((iidx =
find(index)) >= 0) ? myArray(iidx)->myData :
T(0);
102 return ((iidx =
find(index)) >= 0) ? myArray(iidx)->myData :
T(0);
107 template <
typename T>
111 int low, high, mid,
val;
113 high = myArray.entries()-1;
116 return (high == 0 && myArray(0)->myIndex == index) ? 0 : -1;
121 mid = (high+low) >> 1;
122 val = myArray(mid)->myIndex;
123 if (val == index)
return mid;
124 if (val < index) low = mid;
126 }
while (high - low > 1);
127 if (myArray(high)->myIndex == index)
return high;
128 if (myArray(low)->myIndex == index)
return low;
132 #endif // __UT_SparseArrayImpl__
T getRawEntry(int raw_index, int &index)
int find(int index) const
T operator()(unsigned int i)
void removeIndex(int index)
void append(int index, T data)
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool