diff options
author | qrort <qrort@yandex-team.com> | 2022-11-30 23:47:12 +0300 |
---|---|---|
committer | qrort <qrort@yandex-team.com> | 2022-11-30 23:47:12 +0300 |
commit | 22f8ae0e3f5d68b92aecccdf96c1d841a0334311 (patch) | |
tree | bffa27765faf54126ad44bcafa89fadecb7a73d7 /library/cpp/erasure/reed_solomon_isa.h | |
parent | 332b99e2173f0425444abb759eebcb2fafaa9209 (diff) | |
download | ydb-22f8ae0e3f5d68b92aecccdf96c1d841a0334311.tar.gz |
validate canons without yatest_common
Diffstat (limited to 'library/cpp/erasure/reed_solomon_isa.h')
-rw-r--r-- | library/cpp/erasure/reed_solomon_isa.h | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/library/cpp/erasure/reed_solomon_isa.h b/library/cpp/erasure/reed_solomon_isa.h new file mode 100644 index 0000000000..73a3cd630f --- /dev/null +++ b/library/cpp/erasure/reed_solomon_isa.h @@ -0,0 +1,69 @@ +#pragma once + +#include "isa_erasure.h" +#include "reed_solomon.h" + +extern "C" { + #include <contrib/libs/isa-l/include/erasure_code.h> +} + +#include <util/generic/array_ref.h> + +#include <array> + +namespace NErasure { + +template <int DataPartCount, int ParityPartCount, int WordSize, class TCodecTraits> +class TReedSolomonIsa + : public TReedSolomonBase<DataPartCount, ParityPartCount, WordSize, TCodecTraits> +{ + static_assert(WordSize == 8, "ISA-l erasure codes support computations only in GF(2^8)"); +public: + //! Main blob for storing data. + using TBlobType = typename TCodecTraits::TBlobType; + //! Main mutable blob for decoding data. + using TMutableBlobType = typename TCodecTraits::TMutableBlobType; + + TReedSolomonIsa() { + EncodeGFTables_.resize(DataPartCount * ParityPartCount * 32, 0); + GeneratorMatrix_.resize((DataPartCount + ParityPartCount) * DataPartCount, 0); + + gf_gen_rs_matrix( + GeneratorMatrix_.data(), + DataPartCount + ParityPartCount, + DataPartCount); + + ec_init_tables( + DataPartCount, + ParityPartCount, + &GeneratorMatrix_.data()[DataPartCount * DataPartCount], + EncodeGFTables_.data()); + } + + virtual std::vector<TBlobType> Encode(const std::vector<TBlobType>& blocks) const override { + return ISAErasureEncode<DataPartCount, ParityPartCount, TCodecTraits, TBlobType, TMutableBlobType>(EncodeGFTables_, blocks); + } + + virtual std::vector<TBlobType> Decode( + const std::vector<TBlobType>& blocks, + const TPartIndexList& erasedIndices) const override + { + if (erasedIndices.empty()) { + return std::vector<TBlobType>(); + } + + return ISAErasureDecode<DataPartCount, ParityPartCount, TCodecTraits, TBlobType, TMutableBlobType>( + blocks, + erasedIndices, + TConstArrayRef<TPartIndexList>(), + GeneratorMatrix_); + } + + virtual ~TReedSolomonIsa() = default; + +private: + std::vector<unsigned char> GeneratorMatrix_; + std::vector<unsigned char> EncodeGFTables_; +}; + +} // namespace NErasure |