diff --git a/data.cpp b/data.cpp index 7c525e5..ecc587d 100644 --- a/data.cpp +++ b/data.cpp @@ -60,7 +60,7 @@ static asp::Array create_random_array(const size_t& n) noexcept { return std::move(asp::map(original, [& distrib, & gen](const size_t&, const T&) -> const T { return distrib(gen); })); } -int main(int argc, char** argv) { +int32_t main(int32_t argc, char** argv) { asp::toolbox_unit_test(); using array_type = uint16_t; diff --git a/data.hpp b/data.hpp index 584bca8..b762aa6 100644 --- a/data.hpp +++ b/data.hpp @@ -1,6 +1,9 @@ #pragma once #include #include +#ifdef __DEBUG +#include +#endif namespace asp { template @@ -42,8 +45,8 @@ namespace asp { }; template - int print(const Array& a, const char* format) noexcept { - int num_written = 0; + int32_t print(const Array& a, const char* format) noexcept { + int32_t num_written = 0; num_written += printf("["); char formatter[BUFSIZ] = { 0 }; sprintf(formatter, "%s,", format); @@ -54,24 +57,28 @@ namespace asp { return num_written; } - int print(const Array& a) noexcept { + int32_t print(const Array& a) noexcept { + return print(a, "%b"); + } + + int32_t print(const Array& a) noexcept { return print(a, "%i"); } - int print(const Array& a) noexcept { + int32_t print(const Array& a) noexcept { return print(a, "%lu"); } - int print(const Array& a) noexcept { + int32_t print(const Array& a) noexcept { //printf("%i\n", a[0]); return print(a, "%i"); } - int print(const std::string& s) noexcept { + int32_t print(const std::string& s) noexcept { return printf("%s\n", s.c_str()); } - int print(const char* s) noexcept { + int32_t print(const char* s) noexcept { return printf("%s\n", s); } @@ -383,23 +390,23 @@ namespace asp { return mergesort_arg(a, 0, a.length - 1); } - //static void count_sort(const Array& a, const int& exp, const int& d) noexcept { - // Array output(a.length), count(d); - // memset(&count[0], 0, d * sizeof(int)); + //static void count_sort(const Array& a, const int32_t& exp, const int32_t& d) noexcept { + // Array output(a.length), count(d); + // memset(&count[0], 0, d * sizeof(int32_t)); - // foreach(a, [count, exp, d](const int&, const int& val) -> void { + // foreach(a, [count, exp, d](const int32_t&, const int32_t& val) -> void { // count[(val / exp) % d]++; // }); - // for (int i = 1; i <= d; ++i) + // for (int32_t i = 1; i <= d; ++i) // count[i] += count[i - 1]; - // for (int i = a.length - 1; i >= 0; --i) { + // for (int32_t i = a.length - 1; i >= 0; --i) { // output[count[(a[i] / exp) % d] - 1] = a[i]; // count[(a[i] / exp) % d]--; // } - // memcpy(&a[0], &output[0], a.length * sizeof(int)); + // memcpy(&a[0], &output[0], a.length * sizeof(int32_t)); //} template @@ -421,7 +428,7 @@ namespace asp { template inline void radix_sort_256(T* a, const size_t& n) noexcept { //template - //void radix_sort(const Array& a) noexcept { + //void radix_sort(const Array& a) noexcept { if (n <= 1) //if (a.length <= 1) return; @@ -445,7 +452,7 @@ namespace asp { count[i] += count[i - 1]; // Build the output array - for (int i = n - 1; i >= 0; i--) { + for (int32_t i = n - 1; i >= 0; i--) { // precalculate the offset as it's a few instructions const size_t idx = (a[i] >> s) & 0xff; diff --git a/toolbox.cpp b/toolbox.cpp index 434c182..047366c 100644 --- a/toolbox.cpp +++ b/toolbox.cpp @@ -124,8 +124,8 @@ namespace asp { std::string thousand_sep(const uint64_t& k, const char& sep) noexcept { std::string s = "", n = std::to_string(k); - int c = 0; - for (int i = static_cast(n.size()) - 1; i >= 0; --i) { + int32_t c = 0; + for (int32_t i = static_cast(n.size()) - 1; i >= 0; --i) { c++; s.push_back(n[i]); if (c == 3) {