7#include "../utility/utility.hpp"
8#include "../macros.hpp"
16namespace hi::inline
v1 {
23template<
typename T,
typename U,
typename F>
24inline T transform(
const U& input, F operation)
27 result.reserve(input.size());
37template<
typename T, std::
size_t N,
typename F>
43 a.
at(i) = operation(i);
61 hi_axiom(first != last);
65 auto new_last = last - 1;
66 swap(*element, *new_last);
70template<
typename It,
typename UnaryPredicate>
71constexpr It rfind_if(It
const first, It
const last, UnaryPredicate predicate)
83template<
typename It,
typename UnaryPredicate>
84constexpr It rfind_if_not(It
const first, It
const last, UnaryPredicate predicate)
86 return rfind_if(first, last, [&](hilet& x) {
91template<
typename It,
typename T>
92constexpr It rfind(It
const first, It
const last, T
const& value)
94 return rfind_if(first, last, [&](hilet& x) {
106template<
typename It,
typename ItAny>
107[[nodiscard]]
constexpr It
find_any(It data_first, It data_last, ItAny value_first, ItAny value_last)
noexcept
109 return std::find_if(data_first, data_last, [value_first, value_last](hilet& data) {
110 return std::any_of(value_first, value_last, [&data](hilet& value) {
111 return data == value;
122template<
typename ConstIt,
typename It,
typename UnaryPredicate>
123constexpr It
find_cluster(ConstIt last, It start, UnaryPredicate predicate)
125 hilet cluster_id = predicate(*start);
127 for (
auto i = start + 1; i != last; ++i) {
128 if (predicate(*i) != cluster_id) {
141template<
typename ConstIt,
typename It,
typename UnaryPredicate>
142constexpr It
rfind_cluster(ConstIt first, It start, UnaryPredicate predicate)
144 hilet cluster_id = predicate(*start);
146 if (start == first) {
152 if (predicate(*i) != cluster_id) {
171template<
typename ConstIt,
typename It,
typename UnaryPredicate>
182template<
typename It,
typename S,
typename F>
190 if (IsClusterSeperator(*first)) {
194 for (
auto i = first; i != last;) {
198 auto skipOverSeperator = (j == last) ? 0 : 1;
199 i = j + skipOverSeperator;
203template<
typename InputIt1,
typename InputIt2,
typename BinaryPredicate>
205rmismatch(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, BinaryPredicate predicate)
noexcept
211 if (i1 == first1 && i2 == first2) {
212 return {last1, last2};
213 }
else if (i1 == first1) {
214 return {last1, --i2};
215 }
else if (i2 == first2) {
216 return {--i1, last2};
219 if (!predicate(*(--i1), *(--i2))) {
225template<
typename InputIt1,
typename InputIt2>
228 return rmismatch(first1, last1, first2, last2, [&](
auto a,
auto b) {
234T smoothstep(T x)
noexcept
236 x = std::clamp(x, T{0.0}, T{1.0});
237 return x * x * (3 - 2 * x);
241T inverse_smoothstep(T x)
261auto shuffle_by_index(
auto first,
auto last,
auto indices_first,
auto indices_last,
auto index_op)
noexcept
269 src_indices.push_back(i);
273 for (
auto it = indices_first; it != indices_last; ++it, ++dst) {
274 hilet index = index_op(*it);
275 hi_assert_bounds(index, src_indices);
277 auto src = [&src_indices, index]() {
280 src = src_indices[src];
281 }
while (src_indices[src] != index);
287 std::iter_swap(begin(src_indices) + src, begin(src_indices) + dst);
307auto shuffle_by_index(
auto first,
auto last,
auto indices_first,
auto indices_last)
noexcept
309 return shuffle_by_index(first, last, indices_first, indices_last, [](hilet& x) {
322template<
typename DataIt,
typename ValueIt>
343template<
typename DataIt,
typename ValueIt>
366template<std::endian Endian = std::endian::native,
typename T, std::
unsigned_
integral Key>
369 auto base =
table.data();
374 hi_axiom_not_null(base);
391template<std::endian Endian = std::endian::native,
typename T, std::
unsigned_
integral Key>
395 if (ptr ==
nullptr) {
DOXYGEN BUG.
Definition algorithm.hpp:16
constexpr It find_any(It data_first, It data_last, ItAny value_first, ItAny value_last) noexcept
Find the first occurrence of an value in a data.
Definition algorithm.hpp:107
auto shuffle_by_index(auto first, auto last, auto indices_first, auto indices_last, auto index_op) noexcept
Shuffle a container based on a list of indices.
Definition algorithm.hpp:261
DataIt front_strip(DataIt data_first, DataIt data_last, ValueIt value_first, ValueIt value_last) noexcept
Strip data from the front side.
Definition algorithm.hpp:323
constexpr It unordered_remove(It first, It last, It element)
Remove element from a container.
Definition algorithm.hpp:59
constexpr std::pair< It, It > bifind_cluster(ConstIt first, ConstIt last, It start, UnaryPredicate predicate)
Find the begin and end of the current cluster.
Definition algorithm.hpp:172
constexpr T * fast_lower_bound(std::span< T > table, Key const &key) noexcept
The fast lower bound algorithm.
Definition algorithm.hpp:367
constexpr It rfind_cluster(ConstIt first, It start, UnaryPredicate predicate)
Find the start of the current cluster.
Definition algorithm.hpp:142
constexpr It find_cluster(ConstIt last, It start, UnaryPredicate predicate)
Find the start of the current cluster.
Definition algorithm.hpp:123
DataIt back_strip(DataIt data_first, DataIt data_last, ValueIt value_first, ValueIt value_last) noexcept
Strip data from the back side.
Definition algorithm.hpp:344
constexpr T * fast_binary_search_eq(std::span< T > table, Key const &key) noexcept
Search for the item that is equal to the key.
Definition algorithm.hpp:392
constexpr std::array< T, N > generate_array(F operation)
Generate data in an array.
Definition algorithm.hpp:38
void for_each_cluster(It first, It last, S IsClusterSeperator, F Function)
Definition algorithm.hpp:183
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
T back_inserter(T... args)