use constants to avoid mistakes

This commit is contained in:
Ahmet Inan 2018-09-28 10:09:18 +02:00
commit f912be0335
7 changed files with 23 additions and 14 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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();