public.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma once
  2. #include <util/generic/buffer.h>
  3. #include <util/generic/yexception.h>
  4. #include <util/memory/blob.h>
  5. #include <util/string/cast.h>
  6. #include <util/system/src_root.h>
  7. #include <vector>
  8. #include <bitset>
  9. namespace NErasure {
  10. //! The maximum total number of blocks our erasure codec can handle.
  11. static constexpr int MaxTotalPartCount = 16;
  12. //! Max word size to use. `w` in jerasure notation
  13. static constexpr int MaxWordSize = 8;
  14. //! Max threshold to generate bitmask for CanRepair indices for LRC encoding.
  15. static constexpr int BitmaskOptimizationThreshold = 22;
  16. //! A vector type for holding block indexes.
  17. using TPartIndexList = std::vector<int>;
  18. //! Each bit corresponds to a possible block index.
  19. using TPartIndexSet = std::bitset<MaxTotalPartCount>;
  20. template <class TBlobType>
  21. struct ICodec;
  22. struct TDefaultCodecTraits {
  23. using TBlobType = TBlob;
  24. using TMutableBlobType = TBlob;
  25. using TBufferType = TBuffer;
  26. static inline TMutableBlobType AllocateBlob(size_t size) {
  27. TBufferType buffer(size);
  28. buffer.Resize(size);
  29. // The buffer is cleared after this call so no use after free.
  30. return TBlob::FromBuffer(buffer);
  31. }
  32. // AllocateBuffer must fill the memory with 0.
  33. static inline TBufferType AllocateBuffer(size_t size) {
  34. TBufferType buffer(size);
  35. buffer.Fill(0, size);
  36. return buffer;
  37. }
  38. static inline TBlobType FromBufferToBlob(TBufferType&& blob) {
  39. return TBlobType::FromBuffer(blob);
  40. }
  41. };
  42. } // namespace NErasure