mirror of
https://github.com/aicodix/code.git
synced 2026-04-27 22:35:44 +00:00
use compile time constant for size
This commit is contained in:
parent
f6170cc923
commit
3a860b9c73
1 changed files with 6 additions and 4 deletions
10
permute.hh
10
permute.hh
|
|
@ -35,12 +35,14 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename TYPE>
|
template <int SIZE, typename TYPE>
|
||||||
void BitReversalPermute(TYPE *array, int n) {
|
static void BitReversalPermute(TYPE *array)
|
||||||
for (int i = 0, j = 0; i < n - 1; ++i) {
|
{
|
||||||
|
static_assert(SIZE > 0 && (SIZE & (SIZE - 1)) == 0, "SIZE not power of two");
|
||||||
|
for (int i = 0, j = 0; i < SIZE - 1; ++i) {
|
||||||
if (i < j)
|
if (i < j)
|
||||||
std::swap(array[i], array[j]);
|
std::swap(array[i], array[j]);
|
||||||
int k = n >> 1;
|
int k = SIZE >> 1;
|
||||||
while (j & k) {
|
while (j & k) {
|
||||||
j ^= k;
|
j ^= k;
|
||||||
k >>= 1;
|
k >>= 1;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue