13 #ifndef __UT_Algorithm__
14 #define __UT_Algorithm__
25 #include <type_traits>
87 , myShouldReset(false)
89 mySavedHead = myCycle->myHead;
90 mySavedCount = myCycle->myCount;
91 mySavedStartCount = myCycle->myStartCount;
102 myCycle->myHead = mySavedHead;
103 myCycle->myCount = mySavedCount;
104 myCycle->myStartCount = mySavedStartCount;
110 myShouldReset =
true;
116 int64 mySavedStartCount;
128 myCycleDetected =
false;
140 if ((myCount & (myCount - 1)) == 0)
143 myStartCount = myCount;
145 else if (myHead == tail)
147 myCycleDetected =
true;
157 return myCount - myStartCount;
164 bool myCycleDetected;
169 template <
typename T>
183 myStartCount = myCount;
184 myCycleDetected =
false;
189 return myCount - myStartCount;
205 if ((myCount & (myCount - 1)) == 0)
208 myStartCount = myCount - 1;
210 else if (myHead == tail &&
length() >= min_length)
212 myCycleDetected =
true;
226 bool myCycleDetected;
230 template<
typename InputIt>
239 std::for_each(begin, end,
240 [&min, &max](
const input_t &
v)
248 template<
typename InputIt,
typename OutputIt>
259 [&min, &max](
const input_t &
v)
261 return (v-min) / (max-min);
269 #if defined(__clang__) && defined(__x86_64)
271 asm(
"cmpq %1, %2; cmovaeq %4, %0"
284 return b >= a ? src2 : src1;
291 template<
typename ForwardIt,
typename T>
299 size_t half = size / 2;
300 size_t other_half = size -
half;
301 size_t probe = low +
half;
302 size_t other_low = low + other_half;
307 other_half = size -
half;
309 other_low = low + other_half;
314 other_half = size -
half;
316 other_low = low + other_half;
323 size_t half = size / 2;
324 size_t other_half = size -
half;
325 size_t probe = low +
half;
326 size_t other_low = low + other_half;
337 template <
typename Map,
typename Key,
typename CreateValueCB>
338 typename Map::mapped_type &
341 auto it = map.find(key);
343 it = map.emplace(key, create_value()).first;
354 template <
typename Map,
typename Key>
355 typename Map::mapped_type &
359 map, key, []() {
return typename Map::mapped_type(); });
370 template<
class RandomIt,
class RandomFunc>
378 typename std::iterator_traits<RandomIt>::difference_type i,
n;
380 for (i = n; i --> 1; )
383 swap(first[i], first[
r(i+1)]);
void swap(ArAssetInfo &lhs, ArAssetInfo &rhs)
Map::mapped_type & UTfindOrInsert(Map &map, const Key &key, CreateValueCB create_value)
imath_half_bits_t half
if we're in a C-only context, alias the half bits type to half
void swap(UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &a, UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &b)
bool detect(const T &tail)
GLboolean GLboolean GLboolean GLboolean a
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
AutoScope(UT_CycleDetect< T > *cycle)
bool detect(const T &tail, exint min_length=2)
void UTgetArrayMinMax(InputIt begin, InputIt end, typename std::iterator_traits< InputIt >::value_type &min, typename std::iterator_traits< InputIt >::value_type &max)
Get the min/max values of an array.
void UTshuffle(RandomIt first, RandomIt last, RandomFunc &&r)
GLboolean GLboolean GLboolean b
GA_API const UT_StringHolder transform
__hostdev__ uint64_t last(uint32_t i) const
void UTnormalizeArray(InputIt begin, InputIt end, OutputIt d_begin)
Normalize an array.
size_t UTfastSelectLow(T a, T b, size_t src1, size_t src2)
Selects between arguments 'src1/src2' based on the lower of 'a/b'.
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
ForwardIt UTfastUpperBound(ForwardIt first, ForwardIt last, const T &value)
PcpNodeRef_ChildrenIterator begin(const PcpNodeRef::child_const_range &r)
Support for range-based for loops for PcpNodeRef children ranges.