forked from xdsopl/LDPC
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ldpc.hh
111 lines (104 loc) · 1.74 KB
/
ldpc.hh
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
LDPC table iterator
Copyright 2018 Ahmet Inan <[email protected]>
*/
#ifndef LDPC_HH
#define LDPC_HH
struct LDPCInterface
{
virtual LDPCInterface *clone() = 0;
virtual int code_len() = 0;
virtual int data_len() = 0;
virtual int group_len() = 0;
virtual int links_total() = 0;
virtual int links_max_cn() = 0;
virtual int bit_deg() = 0;
virtual int *acc_pos() = 0;
virtual void first_bit() = 0;
virtual void next_bit() = 0;
virtual ~LDPCInterface() = default;
};
template <typename TABLE>
class LDPC : public LDPCInterface
{
static const int M = TABLE::M;
static const int N = TABLE::N;
static const int K = TABLE::K;
static const int R = N-K;
static const int q = R/M;
int acc_pos_[TABLE::DEG_MAX];
const int *row_ptr;
int bit_deg_;
int grp_num;
int grp_len;
int grp_cnt;
int row_cnt;
void next_group()
{
if (grp_cnt >= grp_len) {
grp_len = TABLE::LEN[grp_num];
bit_deg_ = TABLE::DEG[grp_num];
grp_cnt = 0;
++grp_num;
}
for (int i = 0; i < bit_deg_; ++i)
acc_pos_[i] = row_ptr[i];
row_ptr += bit_deg_;
++grp_cnt;
}
public:
LDPCInterface *clone()
{
return new LDPC<TABLE>();
}
int code_len()
{
return N;
}
int data_len()
{
return K;
}
int group_len()
{
return M;
}
int links_total()
{
return TABLE::LINKS_TOTAL;
}
int links_max_cn()
{
return TABLE::LINKS_MAX_CN;
}
int bit_deg()
{
return bit_deg_;
}
int *acc_pos()
{
return acc_pos_;
}
void next_bit()
{
if (++row_cnt < M) {
for (int i = 0; i < bit_deg_; ++i)
acc_pos_[i] += q;
for (int i = 0; i < bit_deg_; ++i)
acc_pos_[i] %= R;
} else {
next_group();
row_cnt = 0;
}
}
void first_bit()
{
grp_num = 0;
grp_len = 0;
grp_cnt = 0;
row_cnt = 0;
row_ptr = TABLE::POS;
next_group();
}
};
#endif