encoding.h

来自「关于Q元LDPC码的C++仿真程序」· C头文件 代码 · 共 123 行

H
123
字号
#ifndef ENCODING
#define ENCODING

/*********************************************************************************
 *
 * Node lists
 *
 *********************************************************************************/

class node;
class variable_node;
class check_node;

class NodeListWithoutID
{
public:
   int CurrentLength;
   int MaxLength;
   node **Nodes;

public:
   NodeListWithoutID() : CurrentLength(0), MaxLength(0), Nodes(NULL)
   {  }

   void Allocate(int p_MaxLength)
   {
      if (Nodes != NULL) delete Nodes;

      Nodes = new node *[p_MaxLength];
      MaxLength = p_MaxLength;
      CurrentLength = 0;
   }

   void Add(node &Node)
   {
      if (CurrentLength >= MaxLength)
      {
         cout << "NodeList:Add: Attempt to exceed list size\n";
         exit(1);
      }
      Nodes[CurrentLength++] = &Node;
   }

   node &ExtractAnyNode()
   {
      if (CurrentLength <= 0)
      {
         cout << "NodeList:ExtractAnyNode: Attempt to extract from an empty list\n";
         exit(1);
      }
      return *Nodes[--CurrentLength];
   }

   ~NodeListWithoutID()
   {
      if (MaxLength > 0)
      {
         delete Nodes;
         MaxLength = 0;
         CurrentLength = 0;
      }
   }

   int GetLength()
   {
      return CurrentLength;
   }

   node &operator[](int i)
   {
      return *Nodes[i];
   }
} ;



class NodeListWithID : public NodeListWithoutID
{
public:
   int Systematic;
   int Gap;
public:
   void SwitchNodes(int i1, int i2);
   void Reverse()
   // Reverse the lists
   {
      for (int i1 = 0, i2 = GetLength() - 1; i1 < i2; i1++, i2--)
         SwitchNodes(i1, i2);
   }
} ;




class VariableNodeList : public NodeListWithID 
{
public:
   void Init(variable_node VariableNodeArray[], int p_Length);
   variable_node &operator[](int i)
   {
      return *(variable_node *)Nodes[i];
   }
} ;





class CheckNodeList : public NodeListWithID 
{
public:
   void Init(check_node CheckNodeArray[], int p_Length);
   check_node &operator[](int i)
   {
      return *(check_node *)Nodes[i];
   }
} ;




#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?