reed_solomon.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #pragma once
  2. #include "helpers.h"
  3. #include <algorithm>
  4. #include <optional>
  5. namespace NErasure {
  6. template <int DataPartCount, int ParityPartCount, int WordSize, class TCodecTraits>
  7. class TReedSolomonBase
  8. : public ICodec<typename TCodecTraits::TBlobType>
  9. {
  10. public:
  11. static constexpr ui64 RequiredDataAlignment = alignof(ui64);
  12. bool CanRepair(const TPartIndexList& erasedIndices) const final {
  13. return erasedIndices.size() <= ParityPartCount;
  14. }
  15. bool CanRepair(const TPartIndexSet& erasedIndices) const final {
  16. return erasedIndices.count() <= static_cast<size_t>(ParityPartCount);
  17. }
  18. std::optional<TPartIndexList> GetRepairIndices(const TPartIndexList& erasedIndices) const final {
  19. if (erasedIndices.empty()) {
  20. return TPartIndexList();
  21. }
  22. TPartIndexList indices = erasedIndices;
  23. std::sort(indices.begin(), indices.end());
  24. indices.erase(std::unique(indices.begin(), indices.end()), indices.end());
  25. if (indices.size() > static_cast<size_t>(ParityPartCount)) {
  26. return std::nullopt;
  27. }
  28. return Difference(0, DataPartCount + ParityPartCount, indices);
  29. }
  30. int GetDataPartCount() const final {
  31. return DataPartCount;
  32. }
  33. int GetParityPartCount() const final {
  34. return ParityPartCount;
  35. }
  36. int GetGuaranteedRepairablePartCount() const final {
  37. return ParityPartCount;
  38. }
  39. int GetWordSize() const final {
  40. return WordSize * sizeof(long);
  41. }
  42. virtual ~TReedSolomonBase() = default;
  43. };
  44. } // namespace NErasure