Added inline and constexpr when possible

This commit is contained in:
saundersp
2024-06-09 22:41:37 +02:00
parent ac6755517b
commit 8058fac200
4 changed files with 108 additions and 107 deletions

View File

@ -4,7 +4,7 @@
#include "data.hpp"
template<typename T>
static bool is_arg_sorted(const asp::Array<T>& a, const asp::Array<size_t>& indices) noexcept {
constexpr static bool is_arg_sorted(const asp::Array<T>& a, const asp::Array<size_t>& indices) noexcept {
for (size_t i = 1; i < a.length; ++i)
if (a[indices[i - 1]] > a[indices[i]])
return false;
@ -12,7 +12,7 @@ static bool is_arg_sorted(const asp::Array<T>& a, const asp::Array<size_t>& indi
}
template<typename T>
static bool is_sorted(const asp::Array<T>& a) noexcept {
constexpr static bool is_sorted(const asp::Array<T>& a) noexcept {
for (size_t i = 1; i < a.length; ++i)
if (a[i - 1] > a[i])
return false;
@ -20,9 +20,9 @@ static bool is_sorted(const asp::Array<T>& a) noexcept {
}
template<typename T>
static void test_sort(const asp::Array<T>& original, void (* const fnc)(const asp::Array<T>&), const char* title) noexcept {
constexpr static void test_sort(const asp::Array<T>& original, void (* const fnc)(const asp::Array<T>&), const char* const title) noexcept {
#ifdef __DEBUG
printf("xxxxxxxxxxxxxxx INGORE COPY ");
printf("xxxxxxxxxxxxxxx IGNORE COPY ");
#endif
const asp::Array<T> a(original);
asp::measure_time_void(title, fnc, a);
@ -36,9 +36,9 @@ static void test_sort(const asp::Array<T>& original, void (* const fnc)(const as
}
template<typename T>
static void test_argsort(const asp::Array<T>& original, asp::Array<size_t>(* const fnc)(const asp::Array<T>&), const char* title) noexcept {
constexpr static void test_argsort(const asp::Array<T>& original, asp::Array<size_t>(* const fnc)(const asp::Array<T>&), const char* const title) noexcept {
#ifdef __DEBUG
printf("xxxxxxxxxxxxxxx INGORE COPY ");
printf("xxxxxxxxxxxxxxx IGNORE COPY ");
#endif
const asp::Array<T> a(original);
const asp::Array<size_t> indices = asp::measure_time<asp::Array<size_t>>(title, fnc, a);
@ -56,8 +56,8 @@ static asp::Array<T> create_random_array(const size_t& n) noexcept {
asp::Array<T> original(n);
std::random_device rd;
std::default_random_engine gen(rd());
std::uniform_int_distribution<T> distrib(std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
return std::move(asp::map(original, [& distrib, & gen](const size_t&, const T&) -> const T { return distrib(gen); }));
std::uniform_int_distribution<T> distribution(std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
return std::move(asp::map(original, [&distribution, &gen](const size_t&, const T&) -> const T { return distribution(gen); }));
}
int32_t main(int32_t argc, char** argv) {