-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathldpc.hh
147 lines (140 loc) · 2.63 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/* -*- c++ -*- */
/*
* Copyright 2018,2019 Ahmet Inan, Ron Economos.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#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