Changed every int to int32_t

This commit is contained in:
saundersp 2023-12-16 08:47:35 +01:00
parent a19787f273
commit 674c5da3cc
3 changed files with 26 additions and 19 deletions

View File

@ -60,7 +60,7 @@ static asp::Array<T> 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); })); 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(); asp::toolbox_unit_test();
using array_type = uint16_t; using array_type = uint16_t;

View File

@ -1,6 +1,9 @@
#pragma once #pragma once
#include <memory> #include <memory>
#include <cstring> #include <cstring>
#ifdef __DEBUG
#include <stdexcept>
#endif
namespace asp { namespace asp {
template<typename T> template<typename T>
@ -42,8 +45,8 @@ namespace asp {
}; };
template<typename T> template<typename T>
int print(const Array<T>& a, const char* format) noexcept { int32_t print(const Array<T>& a, const char* format) noexcept {
int num_written = 0; int32_t num_written = 0;
num_written += printf("["); num_written += printf("[");
char formatter[BUFSIZ] = { 0 }; char formatter[BUFSIZ] = { 0 };
sprintf(formatter, "%s,", format); sprintf(formatter, "%s,", format);
@ -54,24 +57,28 @@ namespace asp {
return num_written; return num_written;
} }
int print(const Array<int>& a) noexcept { int32_t print(const Array<uint16_t>& a) noexcept {
return print(a, "%b");
}
int32_t print(const Array<int32_t>& a) noexcept {
return print(a, "%i"); return print(a, "%i");
} }
int print(const Array<uint64_t>& a) noexcept { int32_t print(const Array<uint64_t>& a) noexcept {
return print(a, "%lu"); return print(a, "%lu");
} }
int print(const Array<int16_t>& a) noexcept { int32_t print(const Array<int16_t>& a) noexcept {
//printf("%i\n", a[0]); //printf("%i\n", a[0]);
return print(a, "%i"); 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()); 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); return printf("%s\n", s);
} }
@ -383,23 +390,23 @@ namespace asp {
return mergesort_arg(a, 0, a.length - 1); return mergesort_arg(a, 0, a.length - 1);
} }
//static void count_sort(const Array<int>& a, const int& exp, const int& d) noexcept { //static void count_sort(const Array<int32_t>& a, const int32_t& exp, const int32_t& d) noexcept {
// Array<int> output(a.length), count(d); // Array<int32_t> output(a.length), count(d);
// memset(&count[0], 0, d * sizeof(int)); // 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]++; // count[(val / exp) % d]++;
// }); // });
// for (int i = 1; i <= d; ++i) // for (int32_t i = 1; i <= d; ++i)
// count[i] += count[i - 1]; // 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]; // output[count[(a[i] / exp) % d] - 1] = a[i];
// count[(a[i] / exp) % d]--; // 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<typename T> template<typename T>
@ -421,7 +428,7 @@ namespace asp {
template<typename T> template<typename T>
inline void radix_sort_256(T* a, const size_t& n) noexcept { inline void radix_sort_256(T* a, const size_t& n) noexcept {
//template<typename T> //template<typename T>
//void radix_sort(const Array<int>& a) noexcept { //void radix_sort(const Array<int32_t>& a) noexcept {
if (n <= 1) if (n <= 1)
//if (a.length <= 1) //if (a.length <= 1)
return; return;
@ -445,7 +452,7 @@ namespace asp {
count[i] += count[i - 1]; count[i] += count[i - 1];
// Build the output array // 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 // precalculate the offset as it's a few instructions
const size_t idx = (a[i] >> s) & 0xff; const size_t idx = (a[i] >> s) & 0xff;

View File

@ -124,8 +124,8 @@ namespace asp {
std::string thousand_sep(const uint64_t& k, const char& sep) noexcept { std::string thousand_sep(const uint64_t& k, const char& sep) noexcept {
std::string s = "", n = std::to_string(k); std::string s = "", n = std::to_string(k);
int c = 0; int32_t c = 0;
for (int i = static_cast<int>(n.size()) - 1; i >= 0; --i) { for (int32_t i = static_cast<int32_t>(n.size()) - 1; i >= 0; --i) {
c++; c++;
s.push_back(n[i]); s.push_back(n[i]);
if (c == 3) { if (c == 3) {