mirror of
https://github.com/aicodix/code.git
synced 2026-04-27 14:30:36 +00:00
use constants to avoid mistakes
This commit is contained in:
parent
5719ff8560
commit
f912be0335
7 changed files with 23 additions and 14 deletions
|
|
@ -12,13 +12,14 @@ Copyright 2018 Ahmet Inan <inan@aicodix.de>
|
|||
|
||||
namespace CODE {
|
||||
|
||||
template <int NR, int FCR, int MSG, typename GF>
|
||||
template <int ROOTS, int FCR, int MSG, typename GF>
|
||||
class BoseChaudhuriHocquenghemDecoder
|
||||
{
|
||||
public:
|
||||
typedef typename GF::value_type value_type;
|
||||
typedef typename GF::ValueType ValueType;
|
||||
typedef typename GF::IndexType IndexType;
|
||||
static const int NR = ROOTS;
|
||||
static const int N = GF::N, K = MSG, NP = N - K;
|
||||
private:
|
||||
ReedSolomonErrorCorrection<NR, FCR, GF> algorithm;
|
||||
|
|
@ -98,13 +99,14 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
template <int NR, int FCR, int MSG, typename GF>
|
||||
template <int ROOTS, int FCR, int MSG, typename GF>
|
||||
class BoseChaudhuriHocquenghemDecoderReference
|
||||
{
|
||||
public:
|
||||
typedef typename GF::value_type value_type;
|
||||
typedef typename GF::ValueType ValueType;
|
||||
typedef typename GF::IndexType IndexType;
|
||||
static const int NR = ROOTS;
|
||||
static const int N = GF::N, K = MSG, NP = N - K;
|
||||
private:
|
||||
ReedSolomonErrorCorrection<NR, FCR, GF> algorithm;
|
||||
|
|
|
|||
|
|
@ -79,15 +79,18 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
template <int NR, int FCR, int MSG, typename GF>
|
||||
template <int ROOTS, int FCR, int MSG, typename GF>
|
||||
class BoseChaudhuriHocquenghemEncoderReference
|
||||
{
|
||||
public:
|
||||
typedef typename GF::value_type value_type;
|
||||
typedef typename GF::ValueType ValueType;
|
||||
typedef typename GF::IndexType IndexType;
|
||||
static const int NR = ROOTS;
|
||||
static const int N = GF::N, K = MSG, NP = N - K;
|
||||
private:
|
||||
ValueType generator[NP+1];
|
||||
public:
|
||||
BoseChaudhuriHocquenghemEncoderReference(std::initializer_list<int> minimal_polynomials)
|
||||
{
|
||||
// $generator(x) = \prod_i(minpoly_i(x))$
|
||||
|
|
|
|||
|
|
@ -11,13 +11,14 @@ Copyright 2018 Ahmet Inan <inan@aicodix.de>
|
|||
|
||||
namespace CODE {
|
||||
|
||||
template <int NR, int FCR, typename GF>
|
||||
template <int ROOTS, int FCR, typename GF>
|
||||
class ReedSolomonDecoder
|
||||
{
|
||||
public:
|
||||
typedef typename GF::value_type value_type;
|
||||
typedef typename GF::ValueType ValueType;
|
||||
typedef typename GF::IndexType IndexType;
|
||||
static const int NR = ROOTS;
|
||||
static const int N = GF::N, K = N - NR, NP = NR;
|
||||
private:
|
||||
ReedSolomonErrorCorrection<NR, FCR, GF> algorithm;
|
||||
|
|
|
|||
|
|
@ -9,15 +9,18 @@ Copyright 2018 Ahmet Inan <inan@aicodix.de>
|
|||
|
||||
namespace CODE {
|
||||
|
||||
template <int NR, int FCR, typename GF>
|
||||
template <int ROOTS, int FCR, typename GF>
|
||||
class ReedSolomonEncoder
|
||||
{
|
||||
public:
|
||||
typedef typename GF::value_type value_type;
|
||||
typedef typename GF::ValueType ValueType;
|
||||
typedef typename GF::IndexType IndexType;
|
||||
static const int NR = ROOTS;
|
||||
static const int N = GF::N, K = N - NR, NP = NR;
|
||||
private:
|
||||
IndexType generator[NR+1];
|
||||
public:
|
||||
ReedSolomonEncoder()
|
||||
{
|
||||
// $generator = \prod_{i=0}^{NR}(x-pe^{FCR+i})$
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ int main()
|
|||
code[i] = target[i];
|
||||
typedef std::uniform_int_distribution<BCH::value_type> distribution;
|
||||
auto noise = std::bind(distribution(0, BCH::N-1), generator);
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
for (int i = 0; i < BCH::NR/2; ++i) {
|
||||
int n = noise();
|
||||
if (n < BCH::K)
|
||||
CODE::xor_be_bit(code, n, 1);
|
||||
|
|
@ -63,7 +63,7 @@ int main()
|
|||
code[i] = target[i];
|
||||
typedef std::uniform_int_distribution<BCH::value_type> distribution;
|
||||
auto noise = std::bind(distribution(0, BCH::N-1), generator);
|
||||
for (int i = 0; i < 12; ++i) {
|
||||
for (int i = 0; i < BCH::NR/2; ++i) {
|
||||
int n = noise();
|
||||
if (n < BCH::K)
|
||||
CODE::xor_be_bit(code, n, 1);
|
||||
|
|
@ -90,7 +90,7 @@ int main()
|
|||
code[i] = target[i];
|
||||
typedef std::uniform_int_distribution<BCH::value_type> distribution;
|
||||
auto noise = std::bind(distribution(0, BCH::N-1), generator);
|
||||
for (int i = 0; i < 3; ++i)
|
||||
for (int i = 0; i < BCH::NR/2; ++i)
|
||||
code[noise()] ^= 1;
|
||||
decode(reinterpret_cast<GF::ValueType *>(code), reinterpret_cast<GF::ValueType *>(code) + BCH::K);
|
||||
for (int i = 0; i < BCH::N; ++i)
|
||||
|
|
@ -113,7 +113,7 @@ int main()
|
|||
code[i] = target[i];
|
||||
typedef std::uniform_int_distribution<BCH::value_type> distribution;
|
||||
auto noise = std::bind(distribution(0, BCH::N-1), generator);
|
||||
for (int i = 0; i < 12; ++i)
|
||||
for (int i = 0; i < BCH::NR/2; ++i)
|
||||
code[noise()] ^= 1;
|
||||
(*decode)(reinterpret_cast<GF::ValueType *>(code), reinterpret_cast<GF::ValueType *>(code) + BCH::K);
|
||||
for (int i = 0; i < BCH::N; ++i)
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ int main()
|
|||
typedef std::uniform_int_distribution<RS::value_type> distribution;
|
||||
auto pos = std::bind(distribution(0, RS::N-1), generator);
|
||||
auto val = std::bind(distribution(0, RS::N), generator);
|
||||
for (int i = 0; i < 2; ++i)
|
||||
for (int i = 0; i < RS::NR/2; ++i)
|
||||
code[pos()] = val();
|
||||
decode(code, code + RS::K);
|
||||
for (int i = 0; i < RS::N; ++i)
|
||||
|
|
@ -51,7 +51,7 @@ int main()
|
|||
typedef std::uniform_int_distribution<RS::value_type> distribution;
|
||||
auto pos = std::bind(distribution(0, RS::N-1), generator);
|
||||
auto val = std::bind(distribution(0, RS::N), generator);
|
||||
for (int i = 0; i < 8; ++i)
|
||||
for (int i = 0; i < RS::NR/2; ++i)
|
||||
code[pos()] = val();
|
||||
decode(code, code + RS::K);
|
||||
for (int i = 0; i < RS::N; ++i)
|
||||
|
|
@ -75,7 +75,7 @@ int main()
|
|||
typedef std::uniform_int_distribution<RS::value_type> distribution;
|
||||
auto pos = std::bind(distribution(0, RS::N-1), generator);
|
||||
auto val = std::bind(distribution(0, RS::N), generator);
|
||||
for (int i = 0; i < 32; ++i)
|
||||
for (int i = 0; i < RS::NR/2; ++i)
|
||||
code[pos()] = val();
|
||||
(*decode)(code, code + RS::K);
|
||||
for (int i = 0; i < RS::N; ++i)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ void rs_test(ENC *encode, DEC *decode, int trials)
|
|||
std::random_device rd;
|
||||
std::default_random_engine generator(rd());
|
||||
typedef std::uniform_int_distribution<typename ENC::value_type> distribution;
|
||||
auto rnd_cnt = std::bind(distribution(0, ENC::NP), generator);
|
||||
auto rnd_cnt = std::bind(distribution(0, ENC::NR), generator);
|
||||
auto rnd_len = std::bind(distribution(1, ENC::K), generator);
|
||||
auto rnd_val = std::bind(distribution(0, ENC::N), generator);
|
||||
while (--trials) {
|
||||
|
|
@ -49,7 +49,7 @@ void rs_test(ENC *encode, DEC *decode, int trials)
|
|||
else
|
||||
parity[pos-data_len] = rnd_val();
|
||||
}
|
||||
int erasures_count = ENC::NP - 2 * error_count;
|
||||
int erasures_count = ENC::NR - 2 * error_count;
|
||||
typename ENC::value_type erasures[erasures_count];
|
||||
for (int i = 0; i < erasures_count; ++i) {
|
||||
int pos = rnd_pos();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue