mirror of
https://github.com/aicodix/code.git
synced 2026-04-27 14:30:36 +00:00
handle data and parity seperate in both BCH and RS
This commit is contained in:
parent
6b3bc5e534
commit
f545b5d6ab
8 changed files with 145 additions and 105 deletions
|
|
@ -33,47 +33,58 @@ private:
|
|||
}
|
||||
}
|
||||
public:
|
||||
int compute_syndromes(ValueType *code, ValueType *syndromes)
|
||||
int compute_syndromes(ValueType *data, ValueType *parity, ValueType *syndromes)
|
||||
{
|
||||
// $syndromes_i = code(pe^{FCR+i})$
|
||||
ValueType coeff(code[0]);
|
||||
ValueType coeff(data[0]);
|
||||
for (int i = 0; i < NR; ++i)
|
||||
syndromes[i] = coeff;
|
||||
update_syndromes(code, syndromes, 1, N);
|
||||
update_syndromes(data, syndromes, 1, K);
|
||||
update_syndromes(parity, syndromes, 0, NP);
|
||||
int nonzero = 0;
|
||||
for (int i = 0; i < NR; ++i)
|
||||
nonzero += !!syndromes[i];
|
||||
return nonzero;
|
||||
}
|
||||
int operator()(ValueType *code, IndexType *erasures = 0, int erasures_count = 0)
|
||||
int operator()(ValueType *data, ValueType *parity, IndexType *erasures = 0, int erasures_count = 0)
|
||||
{
|
||||
assert(0 <= erasures_count && erasures_count <= NR);
|
||||
if (0) {
|
||||
for (int i = 0; i < erasures_count; ++i)
|
||||
code[(int)erasures[i]] = ValueType(0);
|
||||
for (int i = 0; i < erasures_count; ++i) {
|
||||
int idx = (int)erasures[i];
|
||||
if (idx < K)
|
||||
data[idx] = ValueType(0);
|
||||
else
|
||||
parity[idx-K] = ValueType(0);
|
||||
}
|
||||
}
|
||||
ValueType syndromes[NR];
|
||||
if (!compute_syndromes(code, syndromes))
|
||||
if (!compute_syndromes(data, parity, syndromes))
|
||||
return 0;
|
||||
IndexType locations[NR];
|
||||
ValueType magnitudes[NR];
|
||||
int count = algorithm(syndromes, locations, magnitudes, erasures, erasures_count);
|
||||
if (count <= 0)
|
||||
return count;
|
||||
for (int i = 0; i < count; ++i)
|
||||
code[(int)locations[i]] += magnitudes[i];
|
||||
for (int i = 0; i < count; ++i) {
|
||||
int idx = (int)locations[i];
|
||||
if (idx < K)
|
||||
data[idx] += magnitudes[i];
|
||||
else
|
||||
parity[idx-K] += magnitudes[i];
|
||||
}
|
||||
int corrections_count = 0;
|
||||
for (int i = 0; i < count; ++i)
|
||||
corrections_count += !!magnitudes[i];
|
||||
return corrections_count;
|
||||
}
|
||||
int operator()(value_type *code, value_type *erasures = 0, int erasures_count = 0)
|
||||
int operator()(value_type *data, value_type *parity, value_type *erasures = 0, int erasures_count = 0)
|
||||
{
|
||||
return (*this)(reinterpret_cast<ValueType *>(code), reinterpret_cast<IndexType *>(erasures), erasures_count);
|
||||
return (*this)(reinterpret_cast<ValueType *>(data), reinterpret_cast<ValueType *>(parity), reinterpret_cast<IndexType *>(erasures), erasures_count);
|
||||
}
|
||||
int compute_syndromes(value_type *code, value_type *syndromes)
|
||||
int compute_syndromes(value_type *data, value_type *parity, value_type *syndromes)
|
||||
{
|
||||
return compute_syndromes(reinterpret_cast<ValueType *>(code), reinterpret_cast<ValueType *>(syndromes));
|
||||
return compute_syndromes(reinterpret_cast<ValueType *>(data), reinterpret_cast<ValueType *>(parity), reinterpret_cast<ValueType *>(syndromes));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue