Generating permutations and small buffer checks

This commit is contained in:
IlushaShurupov 2023-07-25 20:29:38 +03:00 committed by Ilya Shurupov
parent d3df3dde09
commit 4a5877784b
3 changed files with 33 additions and 2 deletions

View file

@ -318,4 +318,36 @@ namespace tp {
mSize = newSize; mSize = newSize;
} }
}; };
template<typename tType>
void generatePermutations(const Buffer<Buffer<tType>>& in, Buffer<Buffer<tType>>& 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();
}
}
} }

View file

@ -18,8 +18,6 @@ namespace tp {
#define DEBUG_ASSERT(exp) {} #define DEBUG_ASSERT(exp) {}
#endif #endif
#if defined(ENV_OS_WINDOWS) #if defined(ENV_OS_WINDOWS)
#define DEBUG_BREAK(expr) if (expr) { __debugbreak(); } #define DEBUG_BREAK(expr) if (expr) { __debugbreak(); }
#elif defined(ENV_OS_ANDROID) #elif defined(ENV_OS_ANDROID)

1
TODO
View file

@ -30,6 +30,7 @@ Utils:
Containers: Containers:
Add variant size buffer Add variant size buffer
Buffer add resize function
Buffer improvements Buffer improvements
Add mem leakage tests Add mem leakage tests
Add check copy times Add check copy times