aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/erasure/public.h
blob: d5cf01297b16273bbb2450c4190536a3b53177e2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#pragma once

#include <util/generic/buffer.h>
#include <util/generic/yexception.h>
#include <util/memory/blob.h>
#include <util/string/cast.h>
#include <util/system/src_root.h>

#include <vector>

#include <bitset>

namespace NErasure {

//! The maximum total number of blocks our erasure codec can handle.
static constexpr int MaxTotalPartCount = 16;

//! Max word size to use. `w` in jerasure notation
static constexpr int MaxWordSize = 8;

//! Max threshold to generate bitmask for CanRepair indices for LRC encoding.
static constexpr int BitmaskOptimizationThreshold = 22;

//! A vector type for holding block indexes.
using TPartIndexList = std::vector<int>;

//! Each bit corresponds to a possible block index.
using TPartIndexSet = std::bitset<MaxTotalPartCount>;

template <class TBlobType>
struct ICodec;

struct TDefaultCodecTraits {
    using TBlobType = TBlob;
    using TMutableBlobType = TBlob;
    using TBufferType = TBuffer;

    static inline TMutableBlobType AllocateBlob(size_t size) {
        TBufferType buffer(size);
        buffer.Resize(size);
        // The buffer is cleared after this call so no use after free.
        return TBlob::FromBuffer(buffer);
    }

    // AllocateBuffer must fill the memory with 0.
    static inline TBufferType AllocateBuffer(size_t size) {
        TBufferType buffer(size);
        buffer.Fill(0, size);
        return buffer;
    }

    static inline TBlobType FromBufferToBlob(TBufferType&& blob) {
        return TBlobType::FromBuffer(blob);
    }
};

} // namespace NErasure