From 01ba8160ef83481074b8cad80d3e3df395fc4c10 Mon Sep 17 00:00:00 2001 From: IlushaShurupov Date: Tue, 25 Jul 2023 20:29:38 +0300 Subject: [PATCH] Generating permutations and small buffer checks --- Containers/public/Buffer.hpp | 32 ++++++++++++++++++++++++++++++++ Modules/public/Assert.hpp | 2 -- TODO | 1 + 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Containers/public/Buffer.hpp b/Containers/public/Buffer.hpp index 31ab348..b889348 100644 --- a/Containers/public/Buffer.hpp +++ b/Containers/public/Buffer.hpp @@ -318,4 +318,36 @@ namespace tp { mSize = newSize; } }; + + + template + void generatePermutations(const Buffer>& in, Buffer>& out) { + typedef long long Idx; + + // sanity check + for (const auto & vec : in) { + if (!vec.size()) return; + } + + out.resize(in.size()); + auto len = Idx(1); + for (const auto & vec : in) len *= (Idx) vec.size(); + for (auto i = 0; i < in.size(); i++) out[i].resize(len); + + auto dub = Idx(1); + for (auto power = (Idx) in.size() - 1; power >= 0; power--) { + auto& vec = in[power]; + long long i = 0; + while (i < len) { + for (auto val : vec) { + for (auto j = 0; j < dub; j++) { + out[power][i] = val; + i++; + } + } + } + dub *= (Idx) vec.size(); + } + } + } \ No newline at end of file diff --git a/Modules/public/Assert.hpp b/Modules/public/Assert.hpp index c85ac87..f80ad71 100644 --- a/Modules/public/Assert.hpp +++ b/Modules/public/Assert.hpp @@ -18,8 +18,6 @@ namespace tp { #define DEBUG_ASSERT(exp) {} #endif - - #if defined(ENV_OS_WINDOWS) #define DEBUG_BREAK(expr) if (expr) { __debugbreak(); } #elif defined(ENV_OS_ANDROID) diff --git a/TODO b/TODO index cf4062f..c37edc4 100644 --- a/TODO +++ b/TODO @@ -30,6 +30,7 @@ Utils: Containers: Add variant size buffer + Buffer add resize function Buffer improvements Add mem leakage tests Add check copy times