mirror of
https://github.com/aicodix/code.git
synced 2026-04-27 22:35:44 +00:00
improved usability of the new erasure code
This commit is contained in:
parent
8970b8c053
commit
7f492e9d21
3 changed files with 156 additions and 124 deletions
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Regression Test for the second Cauchy Reed Solomon Encoder and Decoder
|
||||
Regression Test for the Cauchy Prime Field Encoder and Decoder
|
||||
|
||||
Copyright 2024 Ahmet Inan <inan@aicodix.de>
|
||||
*/
|
||||
|
|
@ -11,20 +11,20 @@ Copyright 2024 Ahmet Inan <inan@aicodix.de>
|
|||
#include <iostream>
|
||||
#include <functional>
|
||||
#include "prime_field.hh"
|
||||
#include "cauchy_reed_solomon_erasure_coding2.hh"
|
||||
#include "cauchy_prime_field_erasure_coding.hh"
|
||||
|
||||
template <typename TYPE, TYPE PRIME>
|
||||
void crs_test(int trials)
|
||||
template <typename PF, typename IO>
|
||||
void cpf_test(int trials)
|
||||
{
|
||||
int value_bits = log2(PRIME);
|
||||
int value_bytes = value_bits / 8;
|
||||
typedef CODE::PrimeField<TYPE, PRIME> PF;
|
||||
CODE::CauchyReedSolomonErasureCoding2<PF> crs;
|
||||
int value_bytes = sizeof(IO);
|
||||
int value_bits = value_bytes * 8;
|
||||
const int MAX_LEN = std::min<int>(PF::P - 2, 1024);
|
||||
CODE::CauchyPrimeFieldErasureCoding<PF, IO, MAX_LEN> crs;
|
||||
std::random_device rd;
|
||||
std::default_random_engine generator(rd());
|
||||
typedef std::uniform_int_distribution<int> distribution;
|
||||
auto rnd_cnt = std::bind(distribution(1, std::min<int>(PF::P / 4, 256)), generator);
|
||||
auto rnd_len = std::bind(distribution(1, 1 << 10), generator);
|
||||
auto rnd_len = std::bind(distribution(1, MAX_LEN), generator);
|
||||
auto rnd_dat = std::bind(distribution(0, (1 << value_bits) - 1), generator);
|
||||
while (--trials) {
|
||||
int block_count = rnd_cnt();
|
||||
|
|
@ -33,21 +33,21 @@ void crs_test(int trials)
|
|||
int block_bytes = block_values * value_bytes;
|
||||
int data_values = block_count * block_values;
|
||||
int data_bytes = data_values * value_bytes;
|
||||
PF *orig = new PF[data_values];
|
||||
PF *data = new PF[data_values];
|
||||
PF *blocks = new PF[data_values];
|
||||
IO *orig = new IO[data_values];
|
||||
IO *data = new IO[data_values];
|
||||
IO *blocks = new IO[data_values+block_count];
|
||||
for (int i = 0; i < data_values; ++i)
|
||||
orig[i] = PF(rnd_dat());
|
||||
auto identifiers = new PF[identifiers_total];
|
||||
orig[i] = rnd_dat();
|
||||
auto identifiers = new int[identifiers_total];
|
||||
for (int i = 0; i < identifiers_total; ++i)
|
||||
identifiers[i] = PF(block_count + i);
|
||||
identifiers[i] = block_count + i;
|
||||
for (int i = 0; i < block_count; i++) {
|
||||
std::uniform_int_distribution<int> hat(i, identifiers_total - 1);
|
||||
std::swap(identifiers[i], identifiers[hat(generator)]);
|
||||
}
|
||||
auto enc_start = std::chrono::system_clock::now();
|
||||
for (int i = 0; i < block_count; ++i)
|
||||
crs.encode(orig, blocks + block_values * i, identifiers[i](), block_values, block_count);
|
||||
crs.encode(orig, blocks + (block_values+1) * i, identifiers[i], block_values, block_count);
|
||||
auto enc_end = std::chrono::system_clock::now();
|
||||
auto enc_usec = std::chrono::duration_cast<std::chrono::microseconds>(enc_end - enc_start);
|
||||
double enc_mbs = double(data_bytes) / enc_usec.count();
|
||||
|
|
@ -70,12 +70,12 @@ void crs_test(int trials)
|
|||
int main()
|
||||
{
|
||||
if (1) {
|
||||
crs_test<uint32_t, 257>(200);
|
||||
cpf_test<CODE::PrimeField<uint32_t, 257>, uint8_t>(200);
|
||||
}
|
||||
if (1) {
|
||||
crs_test<uint64_t, 65537>(100);
|
||||
cpf_test<CODE::PrimeField<uint64_t, 65537>, uint16_t>(100);
|
||||
}
|
||||
std::cerr << "Cauchy Reed Solomon Two regression test passed!" << std::endl;
|
||||
std::cerr << "Cauchy prime field regression test passed!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue