mirror of
https://github.com/aicodix/code.git
synced 2026-04-27 22:35:44 +00:00
use in-place fast Walsh–Hadamard transform
This commit is contained in:
parent
c0ab2902e8
commit
9b4998a3c5
1 changed files with 20 additions and 25 deletions
|
|
@ -12,38 +12,33 @@ template <int K>
|
|||
class SimplexDecoder
|
||||
{
|
||||
static const int W = 1 << K;
|
||||
static const int N = (1 << K) - 1;
|
||||
int8_t mod[W*N];
|
||||
|
||||
static bool parity(unsigned x)
|
||||
{
|
||||
x ^= x >> 16;
|
||||
x ^= x >> 8;
|
||||
x ^= x >> 4;
|
||||
x ^= x >> 2;
|
||||
x ^= x >> 1;
|
||||
return x & 1;
|
||||
}
|
||||
public:
|
||||
SimplexDecoder()
|
||||
{
|
||||
for (int msg = 0; msg < W; ++msg)
|
||||
for (int i = 0; i < N; ++i)
|
||||
mod[msg*N+i] = 1 - 2 * parity(msg&(i+1));
|
||||
}
|
||||
int operator()(const int8_t *code)
|
||||
{
|
||||
int sum[W] = { code[0], -code[0], };
|
||||
for (int i = 1; i < W; i += 2) {
|
||||
sum[i+1] = code[i] + code[i+1];
|
||||
sum[i+2] = code[i] - code[i+1];
|
||||
}
|
||||
for (int h = 2; h < W; h *= 2) {
|
||||
for (int i = 0; i < W; i += 2 * h) {
|
||||
for (int j = i; j < i + h; ++j) {
|
||||
int x = sum[j] + sum[j+h];
|
||||
int y = sum[j] - sum[j+h];
|
||||
sum[j] = x;
|
||||
sum[j+h] = y;
|
||||
}
|
||||
}
|
||||
}
|
||||
int word = 0, best = 0, next = 0;
|
||||
for (int msg = 0; msg < W; ++msg) {
|
||||
int sum = 0;
|
||||
for (int i = 0; i < N; ++i)
|
||||
sum += mod[msg*N+i] * code[i];
|
||||
if (sum > best) {
|
||||
int mag = sum[msg];
|
||||
if (mag > best) {
|
||||
next = best;
|
||||
best = sum;
|
||||
best = mag;
|
||||
word = msg;
|
||||
} else if (sum > next) {
|
||||
next = sum;
|
||||
} else if (mag > next) {
|
||||
next = mag;
|
||||
}
|
||||
}
|
||||
if (best == next)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue