mirror of
https://github.com/aicodix/code.git
synced 2026-04-27 14:30:36 +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>
|
||||
void BitReversalPermute(TYPE *array, int n) {
|
||||
for (int i = 0, j = 0; i < n - 1; ++i) {
|
||||
template <int SIZE, typename TYPE>
|
||||
static void BitReversalPermute(TYPE *array)
|
||||
{
|
||||
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)
|
||||
std::swap(array[i], array[j]);
|
||||
int k = n >> 1;
|
||||
int k = SIZE >> 1;
|
||||
while (j & k) {
|
||||
j ^= k;
|
||||
k >>= 1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue