mirror of
https://github.com/aicodix/code.git
synced 2026-04-27 22:35:44 +00:00
reduced code duplication with lambda update()
This commit is contained in:
parent
8c2e824b4e
commit
619d8bd3b4
1 changed files with 15 additions and 30 deletions
|
|
@ -70,21 +70,24 @@ public:
|
||||||
// metric of hard decision
|
// metric of hard decision
|
||||||
int best = metric(code, word);
|
int best = metric(code, word);
|
||||||
int next = -1;
|
int next = -1;
|
||||||
|
auto update = [code, &word, &best, &next](int hard) {
|
||||||
|
if (hard == word)
|
||||||
|
return;
|
||||||
|
int met = metric(code, hard);
|
||||||
|
if (met > best) {
|
||||||
|
next = best;
|
||||||
|
best = met;
|
||||||
|
word = hard;
|
||||||
|
} else if (met > next) {
|
||||||
|
next = met;
|
||||||
|
}
|
||||||
|
};
|
||||||
// flip each bit and see ..
|
// flip each bit and see ..
|
||||||
if (0) {
|
if (0) {
|
||||||
for (int j = 0; j < N; ++j) {
|
for (int j = 0; j < N; ++j) {
|
||||||
int tmp = 1 << j;
|
int tmp = 1 << j;
|
||||||
int dec = (*this)(cw ^ tmp);
|
int dec = (*this)(cw ^ tmp);
|
||||||
if (dec == word)
|
update(dec);
|
||||||
continue;
|
|
||||||
int met = metric(code, dec);
|
|
||||||
if (met > best) {
|
|
||||||
next = best;
|
|
||||||
best = met;
|
|
||||||
word = dec;
|
|
||||||
} else if (met > next) {
|
|
||||||
next = met;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Chase algorithm
|
// Chase algorithm
|
||||||
|
|
@ -104,32 +107,14 @@ public:
|
||||||
for (int i = 0; i < T; ++i)
|
for (int i = 0; i < T; ++i)
|
||||||
tmp |= ((j>>i)&1) << worst[i];
|
tmp |= ((j>>i)&1) << worst[i];
|
||||||
int dec = (*this)(cw ^ tmp);
|
int dec = (*this)(cw ^ tmp);
|
||||||
if (dec == word)
|
update(dec);
|
||||||
continue;
|
|
||||||
int met = metric(code, dec);
|
|
||||||
if (met > best) {
|
|
||||||
next = best;
|
|
||||||
best = met;
|
|
||||||
word = dec;
|
|
||||||
} else if (met > next) {
|
|
||||||
next = met;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// maximum likelihood
|
// maximum likelihood
|
||||||
if (K <= 6) {
|
if (K <= 6) {
|
||||||
for (int msg = 0; msg < W; ++msg) {
|
for (int msg = 0; msg < W; ++msg) {
|
||||||
int enc = (msg << P) | par[msg];
|
int enc = (msg << P) | par[msg];
|
||||||
if (enc == word)
|
update(enc);
|
||||||
continue;
|
|
||||||
int met = metric(code, enc);
|
|
||||||
if (met > best) {
|
|
||||||
next = best;
|
|
||||||
best = met;
|
|
||||||
word = enc;
|
|
||||||
} else if (met > next) {
|
|
||||||
next = met;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (best == next)
|
if (best == next)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue