📄 expandmatrix.cpp
字号:
#include "parameter_sets.h"
int ExpandMatrixF(struct BasicParaS * ctrl)
{
int i, j, k, temp;
int z0; // z0 is the maximum value of z factor
struct LinkNode * * * currentNode = new struct LinkNode * *[ctrl->zfactor];
struct LinkNode * c;
z0 = 640;
for (i=0; i<ctrl->numRows; i++)
{
for (j=0; j<ctrl->numCols; j++)
{
if (ctrl->basicH[i][j] <= 0)
{
ctrl->expandedH[i][j] = ctrl->basicH[i][j];
}
else
{
ctrl->expandedH[i][j] = (ctrl->basicH[i][j]*ctrl->zfactor)/z0; //见协议内容
}
}
}
if (ctrl->mode == 1)
{
printf("The expanded matrix is ..\n");
for (i=0; i<ctrl->numRows; i++)
{
for (j=0; j<ctrl->numCols; j++)
{
printf(" %2d", ctrl->expandedH[i][j]);
}
printf("\n");
}
}
// Build a cross-link to record the H matrix
ctrl->rowLink = new struct LinkNode *[ctrl->numChk];
ctrl->colLink = new struct LinkNode *[ctrl->numOutBits];
// Insert the head node per row into the row link
for (i=0; i<ctrl->numRows; i++) {
for (k=0; k<ctrl->zfactor; k++) {
*(currentNode+k) = ctrl->rowLink+i*ctrl->zfactor+k;
}
for (j=0; j<ctrl->numCols; j++) {
if (ctrl->expandedH[i][j] >= 0) {
for (k=0; k<ctrl->zfactor; k++) {
temp = (k+ctrl->expandedH[i][j])%ctrl->zfactor;
*(*(currentNode+k)) = new struct LinkNode;
(*(*(currentNode+k)))->rowIdx = i*ctrl->zfactor+k;
(*(*(currentNode+k)))->colIdx = j*ctrl->zfactor+temp;
(*(*(currentNode+k)))->rowPtr = NULL;
(*(*(currentNode+k)))->colPtr = NULL;
(*(*(currentNode+k)))->rMsg[0] = 0;
(*(*(currentNode+k)))->rMsg[1] = 0;
(*(*(currentNode+k)))->qMsg[0] = 0;
(*(*(currentNode+k)))->qMsg[1] = 0;
*(currentNode+k) = &((*(*(currentNode+k)))->rowPtr);
}
}
}
}
// Link the nodes in the same column
for (i=0; i<ctrl->numCols; i++) {
for (k=0; k<ctrl->zfactor; k++) {
*(currentNode+k) = ctrl->colLink+i*ctrl->zfactor+k;
}
for (j=0; j<ctrl->numRows; j++) {
if (ctrl->expandedH[j][i] >= 0) {
for (k=0; k<ctrl->zfactor; k++) {
temp = (k+ctrl->zfactor-ctrl->expandedH[j][i])%ctrl->zfactor;
c = *(ctrl->rowLink+j*ctrl->zfactor+temp);
while (c->colIdx != (i*ctrl->zfactor+k)) {
c = c->rowPtr;
}
*(*(currentNode+k)) = c;
*(currentNode+k) = &(c->colPtr);
}
}
}
}
delete [] currentNode;
if (ctrl->mode == 1)
{
printf("This is the cross link per row ..\n");
for (i=0; i<ctrl->numChk; i++)
{
c = *(ctrl->rowLink+i);
while (c != NULL)
{
printf("(%d,%d)->", c->rowIdx, c->colIdx);
c = c->rowPtr;
}
printf("End of Row\n");
}
printf("This is the cross link per col ..\n");
for (i=0; i<ctrl->numOutBits; i++)
{
c = *(ctrl->colLink+i);
while (c != NULL)
{
printf("(%d,%d)->", c->rowIdx, c->colIdx);
c = c->colPtr;
}
printf("End of Col\n");
}
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -