| 206 | namespace cpu_impl { |
| 207 | template <typename InIt, typename OutIt, typename Comp> |
| 208 | void ArgSort(InIt in_first, InIt in_last, OutIt out_first, Comp comp = std::less{}) { |
| 209 | auto n = std::distance(in_first, in_last); |
| 210 | using Idx = typename std::iterator_traits<OutIt>::value_type; |
| 211 | |
| 212 | auto out_last = out_first + n; |
| 213 | std::iota(out_first, out_last, 0); |
| 214 | auto op = [&](Idx const &l, Idx const &r) { |
| 215 | return comp(in_first[l], in_first[r]); |
| 216 | }; |
| 217 | std::stable_sort(out_first, out_last, op); |
| 218 | } |
| 219 | |
| 220 | [[nodiscard]] inline std::int32_t SearchSorted(CatStrArrayView haystack, |
| 221 | Span<std::int32_t const> ref_sorted_idx, |