Generating permutations and small buffer checks
This commit is contained in:
parent
939e365a4f
commit
01ba8160ef
3 changed files with 33 additions and 2 deletions
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -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
1
TODO
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue