File indexing completed on 2025-01-30 06:07:56
0001 #ifndef HeterogeneousCore_AlpakaInterface_interface_alpakastdAlgorithm_h
0002 #define HeterogeneousCore_AlpakaInterface_interface_alpakastdAlgorithm_h
0003
0004 #include <algorithm>
0005 #include <functional>
0006 #include <utility>
0007
0008 #include <alpaka/alpaka.hpp>
0009
0010
0011
0012 namespace alpaka_std {
0013
0014 template <typename RandomIt, typename T, typename Compare = std::less<T>>
0015 ALPAKA_FN_HOST_ACC constexpr RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp = {}) {
0016 auto count = last - first;
0017
0018 while (count > 0) {
0019 auto it = first;
0020 auto step = count / 2;
0021 it += step;
0022 if (comp(*it, value)) {
0023 first = ++it;
0024 count -= step + 1;
0025 } else {
0026 count = step;
0027 }
0028 }
0029 return first;
0030 }
0031
0032 template <typename RandomIt, typename T, typename Compare = std::less<T>>
0033 ALPAKA_FN_HOST_ACC constexpr RandomIt upper_bound(RandomIt first, RandomIt last, const T &value, Compare comp = {}) {
0034 auto count = last - first;
0035
0036 while (count > 0) {
0037 auto it = first;
0038 auto step = count / 2;
0039 it += step;
0040 if (!comp(value, *it)) {
0041 first = ++it;
0042 count -= step + 1;
0043 } else {
0044 count = step;
0045 }
0046 }
0047 return first;
0048 }
0049
0050 }
0051
0052 #endif