mirror of
https://github.com/aicodix/code.git
synced 2026-04-27 22:35:44 +00:00
use const on args to improve readability
This commit is contained in:
parent
ea07a593d7
commit
d196187187
7 changed files with 24 additions and 24 deletions
|
|
@ -29,12 +29,12 @@ void set_le_bit(uint8_t *buf, int pos, bool val)
|
||||||
buf[pos/8] = (~(1<<(pos%8))&buf[pos/8])|(val<<(pos%8));
|
buf[pos/8] = (~(1<<(pos%8))&buf[pos/8])|(val<<(pos%8));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get_be_bit(uint8_t *buf, int pos)
|
bool get_be_bit(const uint8_t *buf, int pos)
|
||||||
{
|
{
|
||||||
return (buf[pos/8]>>(7-pos%8))&1;
|
return (buf[pos/8]>>(7-pos%8))&1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get_le_bit(uint8_t *buf, int pos)
|
bool get_le_bit(const uint8_t *buf, int pos)
|
||||||
{
|
{
|
||||||
return (buf[pos/8]>>(pos%8))&1;
|
return (buf[pos/8]>>(pos%8))&1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ public:
|
||||||
static const int N = GF::N, K = MSG, NP = N - K;
|
static const int N = GF::N, K = MSG, NP = N - K;
|
||||||
private:
|
private:
|
||||||
ReedSolomonErrorCorrection<NR, FCR, GF> algorithm;
|
ReedSolomonErrorCorrection<NR, FCR, GF> algorithm;
|
||||||
void update_syndromes(uint8_t *poly, ValueType *syndromes, int begin, int end)
|
void update_syndromes(const uint8_t *poly, ValueType *syndromes, int begin, int end)
|
||||||
{
|
{
|
||||||
for (int j = begin; j < end; ++j) {
|
for (int j = begin; j < end; ++j) {
|
||||||
ValueType coeff(get_be_bit(poly, j));
|
ValueType coeff(get_be_bit(poly, j));
|
||||||
|
|
@ -35,7 +35,7 @@ private:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
int compute_syndromes(uint8_t *data, uint8_t *parity, ValueType *syndromes, int data_len = K)
|
int compute_syndromes(const uint8_t *data, const uint8_t *parity, ValueType *syndromes, int data_len = K)
|
||||||
{
|
{
|
||||||
assert(0 < data_len && data_len <= K);
|
assert(0 < data_len && data_len <= K);
|
||||||
// $syndromes_i = code(pe^{FCR+i})$
|
// $syndromes_i = code(pe^{FCR+i})$
|
||||||
|
|
@ -49,7 +49,7 @@ public:
|
||||||
nonzero += !!syndromes[i];
|
nonzero += !!syndromes[i];
|
||||||
return nonzero;
|
return nonzero;
|
||||||
}
|
}
|
||||||
int compute_syndromes(uint8_t *data, uint8_t *parity, value_type *syndromes, int data_len = K)
|
int compute_syndromes(const uint8_t *data, const uint8_t *parity, value_type *syndromes, int data_len = K)
|
||||||
{
|
{
|
||||||
return compute_syndromes(data, parity, reinterpret_cast<ValueType *>(syndromes), data_len);
|
return compute_syndromes(data, parity, reinterpret_cast<ValueType *>(syndromes), data_len);
|
||||||
}
|
}
|
||||||
|
|
@ -110,7 +110,7 @@ public:
|
||||||
static const int N = GF::N, K = MSG, NP = N - K;
|
static const int N = GF::N, K = MSG, NP = N - K;
|
||||||
private:
|
private:
|
||||||
ReedSolomonErrorCorrection<NR, FCR, GF> algorithm;
|
ReedSolomonErrorCorrection<NR, FCR, GF> algorithm;
|
||||||
void update_syndromes(ValueType *poly, ValueType *syndromes, int begin, int end)
|
void update_syndromes(const ValueType *poly, ValueType *syndromes, int begin, int end)
|
||||||
{
|
{
|
||||||
for (int j = begin; j < end; ++j) {
|
for (int j = begin; j < end; ++j) {
|
||||||
ValueType coeff(poly[j]);
|
ValueType coeff(poly[j]);
|
||||||
|
|
@ -122,7 +122,7 @@ private:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
int compute_syndromes(ValueType *data, ValueType *parity, ValueType *syndromes, int data_len = K)
|
int compute_syndromes(const ValueType *data, const ValueType *parity, ValueType *syndromes, int data_len = K)
|
||||||
{
|
{
|
||||||
assert(0 < data_len && data_len <= K);
|
assert(0 < data_len && data_len <= K);
|
||||||
// $syndromes_i = code(pe^{FCR+i})$
|
// $syndromes_i = code(pe^{FCR+i})$
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ public:
|
||||||
set_be_bit(generator, i, get_be_bit(generator, i+1));
|
set_be_bit(generator, i, get_be_bit(generator, i+1));
|
||||||
set_be_bit(generator, NP, 0);
|
set_be_bit(generator, NP, 0);
|
||||||
}
|
}
|
||||||
void operator()(uint8_t *data, uint8_t *parity, int data_len = K)
|
void operator()(const uint8_t *data, uint8_t *parity, int data_len = K)
|
||||||
{
|
{
|
||||||
assert(0 < data_len && data_len <= K);
|
assert(0 < data_len && data_len <= K);
|
||||||
// $code = data * x^{NP} + (data * x^{NP}) \mod{generator}$
|
// $code = data * x^{NP} + (data * x^{NP}) \mod{generator}$
|
||||||
|
|
@ -129,7 +129,7 @@ public:
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void operator()(ValueType *data, ValueType *parity, int data_len = K)
|
void operator()(const ValueType *data, ValueType *parity, int data_len = K)
|
||||||
{
|
{
|
||||||
assert(0 < data_len && data_len <= K);
|
assert(0 < data_len && data_len <= K);
|
||||||
// $code = data * x^{NP} + (data * x^{NP}) \mod{generator}$
|
// $code = data * x^{NP} + (data * x^{NP}) \mod{generator}$
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void operator()(int8_t *data, int8_t *parity)
|
void operator()(const int8_t *data, int8_t *parity)
|
||||||
{
|
{
|
||||||
int8_t tmp = 1;
|
int8_t tmp = 1;
|
||||||
for (int j = 0; j < M; ++j) {
|
for (int j = 0; j < M; ++j) {
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ public:
|
||||||
static const int N = GF::N, K = N - NR, NP = NR;
|
static const int N = GF::N, K = N - NR, NP = NR;
|
||||||
private:
|
private:
|
||||||
ReedSolomonErrorCorrection<NR, FCR, GF> algorithm;
|
ReedSolomonErrorCorrection<NR, FCR, GF> algorithm;
|
||||||
void update_syndromes(ValueType *poly, ValueType *syndromes, int begin, int end)
|
void update_syndromes(const ValueType *poly, ValueType *syndromes, int begin, int end)
|
||||||
{
|
{
|
||||||
for (int j = begin; j < end; ++j) {
|
for (int j = begin; j < end; ++j) {
|
||||||
ValueType coeff(poly[j]);
|
ValueType coeff(poly[j]);
|
||||||
|
|
@ -34,7 +34,7 @@ private:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
int compute_syndromes(ValueType *data, ValueType *parity, ValueType *syndromes, int data_len = K)
|
int compute_syndromes(const ValueType *data, const ValueType *parity, ValueType *syndromes, int data_len = K)
|
||||||
{
|
{
|
||||||
assert(0 < data_len && data_len <= K);
|
assert(0 < data_len && data_len <= K);
|
||||||
// $syndromes_i = code(pe^{FCR+i})$
|
// $syndromes_i = code(pe^{FCR+i})$
|
||||||
|
|
@ -92,9 +92,9 @@ public:
|
||||||
{
|
{
|
||||||
return (*this)(reinterpret_cast<ValueType *>(data), reinterpret_cast<ValueType *>(parity), reinterpret_cast<IndexType *>(erasures), erasures_count, data_len);
|
return (*this)(reinterpret_cast<ValueType *>(data), reinterpret_cast<ValueType *>(parity), reinterpret_cast<IndexType *>(erasures), erasures_count, data_len);
|
||||||
}
|
}
|
||||||
int compute_syndromes(value_type *data, value_type *parity, value_type *syndromes, int data_len = K)
|
int compute_syndromes(const value_type *data, const value_type *parity, value_type *syndromes, int data_len = K)
|
||||||
{
|
{
|
||||||
return compute_syndromes(reinterpret_cast<ValueType *>(data), reinterpret_cast<ValueType *>(parity), reinterpret_cast<ValueType *>(syndromes), data_len);
|
return compute_syndromes(reinterpret_cast<const ValueType *>(data), reinterpret_cast<const ValueType *>(parity), reinterpret_cast<ValueType *>(syndromes), data_len);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ public:
|
||||||
for (int i = 0; i <= NR; ++i)
|
for (int i = 0; i <= NR; ++i)
|
||||||
generator[i] = index(tmp[i]);
|
generator[i] = index(tmp[i]);
|
||||||
}
|
}
|
||||||
void operator()(ValueType *data, ValueType *parity, int data_len = K)
|
void operator()(const ValueType *data, ValueType *parity, int data_len = K)
|
||||||
{
|
{
|
||||||
assert(0 < data_len && data_len <= K);
|
assert(0 < data_len && data_len <= K);
|
||||||
// $code = data * x^{NR} + (data * x^{NR}) \mod{generator}$
|
// $code = data * x^{NR} + (data * x^{NR}) \mod{generator}$
|
||||||
|
|
@ -71,9 +71,9 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void operator()(value_type *data, value_type *parity, int data_len = K)
|
void operator()(const value_type *data, value_type *parity, int data_len = K)
|
||||||
{
|
{
|
||||||
(*this)(reinterpret_cast<ValueType *>(data), reinterpret_cast<ValueType *>(parity), data_len);
|
(*this)(reinterpret_cast<const ValueType *>(data), reinterpret_cast<ValueType *>(parity), data_len);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ struct Chien
|
||||||
{
|
{
|
||||||
typedef typename GF::ValueType ValueType;
|
typedef typename GF::ValueType ValueType;
|
||||||
typedef typename GF::IndexType IndexType;
|
typedef typename GF::IndexType IndexType;
|
||||||
static int search(ValueType *locator, int locator_degree, IndexType *locations)
|
static int search(const ValueType *locator, int locator_degree, IndexType *locations)
|
||||||
{
|
{
|
||||||
ValueType tmp[locator_degree+1];
|
ValueType tmp[locator_degree+1];
|
||||||
for (int i = 0; i <= locator_degree; ++i)
|
for (int i = 0; i <= locator_degree; ++i)
|
||||||
|
|
@ -65,7 +65,7 @@ struct LocationFinder
|
||||||
typedef typename GF::ValueType ValueType;
|
typedef typename GF::ValueType ValueType;
|
||||||
typedef typename GF::IndexType IndexType;
|
typedef typename GF::IndexType IndexType;
|
||||||
ArtinSchreier<GF> imap;
|
ArtinSchreier<GF> imap;
|
||||||
int operator()(ValueType *locator, int locator_degree, IndexType *locations)
|
int operator()(const ValueType *locator, int locator_degree, IndexType *locations)
|
||||||
{
|
{
|
||||||
if (locator_degree == 1) {
|
if (locator_degree == 1) {
|
||||||
locations[0] = (index(locator[0]) / index(locator[1])) / IndexType(1);
|
locations[0] = (index(locator[0]) / index(locator[1])) / IndexType(1);
|
||||||
|
|
@ -91,7 +91,7 @@ struct Forney
|
||||||
{
|
{
|
||||||
typedef typename GF::ValueType ValueType;
|
typedef typename GF::ValueType ValueType;
|
||||||
typedef typename GF::IndexType IndexType;
|
typedef typename GF::IndexType IndexType;
|
||||||
static int compute_evaluator(ValueType *syndromes, ValueType *locator, int locator_degree, ValueType *evaluator)
|
static int compute_evaluator(const ValueType *syndromes, const ValueType *locator, int locator_degree, ValueType *evaluator)
|
||||||
{
|
{
|
||||||
// $evaluator = (syndromes * locator) \bmod{x^{NR}}$
|
// $evaluator = (syndromes * locator) \bmod{x^{NR}}$
|
||||||
int tmp = std::min(locator_degree, NR-1);
|
int tmp = std::min(locator_degree, NR-1);
|
||||||
|
|
@ -105,7 +105,7 @@ struct Forney
|
||||||
}
|
}
|
||||||
return degree;
|
return degree;
|
||||||
}
|
}
|
||||||
static void compute_magnitudes(ValueType *locator, IndexType *locations, int count, ValueType *evaluator, int evaluator_degree, ValueType *magnitudes)
|
static void compute_magnitudes(const ValueType *locator, const IndexType *locations, int count, const ValueType *evaluator, int evaluator_degree, ValueType *magnitudes)
|
||||||
{
|
{
|
||||||
// $magnitude = root^{FCR-1} * \frac{evaluator(root)}{locator'(root)}$
|
// $magnitude = root^{FCR-1} * \frac{evaluator(root)}{locator'(root)}$
|
||||||
for (int i = 0; i < count; ++i) {
|
for (int i = 0; i < count; ++i) {
|
||||||
|
|
@ -134,7 +134,7 @@ struct Forney
|
||||||
magnitudes[i] = value(magnitude);
|
magnitudes[i] = value(magnitude);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static int algorithm(ValueType *syndromes, ValueType *locator, IndexType *locations, int count, ValueType *evaluator, ValueType *magnitudes)
|
static int algorithm(const ValueType *syndromes, const ValueType *locator, const IndexType *locations, int count, ValueType *evaluator, ValueType *magnitudes)
|
||||||
{
|
{
|
||||||
int evaluator_degree = compute_evaluator(syndromes, locator, count, evaluator);
|
int evaluator_degree = compute_evaluator(syndromes, locator, count, evaluator);
|
||||||
compute_magnitudes(locator, locations, count, evaluator, evaluator_degree, magnitudes);
|
compute_magnitudes(locator, locations, count, evaluator, evaluator_degree, magnitudes);
|
||||||
|
|
@ -147,7 +147,7 @@ struct BerlekampMassey
|
||||||
{
|
{
|
||||||
typedef typename GF::ValueType ValueType;
|
typedef typename GF::ValueType ValueType;
|
||||||
typedef typename GF::IndexType IndexType;
|
typedef typename GF::IndexType IndexType;
|
||||||
static int algorithm(ValueType *s, ValueType *C, int count = 0)
|
static int algorithm(const ValueType *s, ValueType *C, int count = 0)
|
||||||
{
|
{
|
||||||
ValueType B[NR+1];
|
ValueType B[NR+1];
|
||||||
for (int i = 0; i <= NR; ++i)
|
for (int i = 0; i <= NR; ++i)
|
||||||
|
|
@ -189,7 +189,7 @@ struct ReedSolomonErrorCorrection
|
||||||
typedef typename GF::ValueType ValueType;
|
typedef typename GF::ValueType ValueType;
|
||||||
typedef typename GF::IndexType IndexType;
|
typedef typename GF::IndexType IndexType;
|
||||||
RS::LocationFinder<NR, GF> search;
|
RS::LocationFinder<NR, GF> search;
|
||||||
int operator()(ValueType *syndromes, IndexType *locations, ValueType *magnitudes, IndexType *erasures = 0, int erasures_count = 0)
|
int operator()(const ValueType *syndromes, IndexType *locations, ValueType *magnitudes, const IndexType *erasures = 0, int erasures_count = 0)
|
||||||
{
|
{
|
||||||
assert(0 <= erasures_count && erasures_count <= NR);
|
assert(0 <= erasures_count && erasures_count <= NR);
|
||||||
ValueType locator[NR+1];
|
ValueType locator[NR+1];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue