aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/erasure/reed_solomon.h
diff options
context:
space:
mode:
authorqrort <qrort@yandex-team.com>2022-11-30 23:47:12 +0300
committerqrort <qrort@yandex-team.com>2022-11-30 23:47:12 +0300
commit22f8ae0e3f5d68b92aecccdf96c1d841a0334311 (patch)
treebffa27765faf54126ad44bcafa89fadecb7a73d7 /library/cpp/erasure/reed_solomon.h
parent332b99e2173f0425444abb759eebcb2fafaa9209 (diff)
downloadydb-22f8ae0e3f5d68b92aecccdf96c1d841a0334311.tar.gz
validate canons without yatest_common
Diffstat (limited to 'library/cpp/erasure/reed_solomon.h')
-rw-r--r--library/cpp/erasure/reed_solomon.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/library/cpp/erasure/reed_solomon.h b/library/cpp/erasure/reed_solomon.h
new file mode 100644
index 0000000000..a2e268e81d
--- /dev/null
+++ b/library/cpp/erasure/reed_solomon.h
@@ -0,0 +1,60 @@
+#pragma once
+
+#include "helpers.h"
+
+#include <algorithm>
+#include <optional>
+
+namespace NErasure {
+
+template <int DataPartCount, int ParityPartCount, int WordSize, class TCodecTraits>
+class TReedSolomonBase
+ : public ICodec<typename TCodecTraits::TBlobType>
+{
+public:
+ static constexpr ui64 RequiredDataAlignment = alignof(ui64);
+
+ bool CanRepair(const TPartIndexList& erasedIndices) const final {
+ return erasedIndices.size() <= ParityPartCount;
+ }
+
+ bool CanRepair(const TPartIndexSet& erasedIndices) const final {
+ return erasedIndices.count() <= static_cast<size_t>(ParityPartCount);
+ }
+
+ std::optional<TPartIndexList> GetRepairIndices(const TPartIndexList& erasedIndices) const final {
+ if (erasedIndices.empty()) {
+ return TPartIndexList();
+ }
+
+ TPartIndexList indices = erasedIndices;
+ std::sort(indices.begin(), indices.end());
+ indices.erase(std::unique(indices.begin(), indices.end()), indices.end());
+
+ if (indices.size() > static_cast<size_t>(ParityPartCount)) {
+ return std::nullopt;
+ }
+
+ return Difference(0, DataPartCount + ParityPartCount, indices);
+ }
+
+ int GetDataPartCount() const final {
+ return DataPartCount;
+ }
+
+ int GetParityPartCount() const final {
+ return ParityPartCount;
+ }
+
+ int GetGuaranteedRepairablePartCount() const final {
+ return ParityPartCount;
+ }
+
+ int GetWordSize() const final {
+ return WordSize * sizeof(long);
+ }
+
+ virtual ~TReedSolomonBase() = default;
+};
+
+} // namespace NErasure