⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rm_64.h

📁 This CD-ROM is distributed by Kluwer Academic Publishers with ABSOLUTELY NO SUPPORT and NO WARRANTY
💻 H
字号:
//class RM_Code will construct G(k*N) that contains the code length n and the message length k.





#include <iostream.h>

#include <math.h>



const int ROW = 58;

const int COLUMN = 65;



class RM_64

{

 private:

  int n;   //the code length n=2 pow(m)

  int k;   //the message length k=C(m,0)+C(m,1)+...+C(m,r)

  int r;

  int m;

  int G[ROW][COLUMN];

  void set_G_matrix();  //k, n, m

  int cal_factorial(int);   //calculate factorial

  int cal_combination(int, int);   //calculate combination

  void multiply ( int *, int *, int *, int);

  

 public:

  RM_64(int, int);//r and m

  void set_n(int);

  void set_k(int, int);//r and m

  int get_n ();

  int get_k ();

  const int* get_G();

  void display() const;//display G_matrix

};





RM_64::RM_64(int _m, int _r) //constructor

{

  set_n(_m);

  set_k(_m, _r);

  m = _m;  r = _r;

  

  for (int i = 0; i < k; i++)

    for(int j = 0; j < n; j++)

      G[i][j] = 0;

		  

  set_G_matrix();//initialize the G_matrix

}





int RM_64::cal_factorial(int fac)

{

  if (fac ==0 )

    return 1;

   if (fac == 1) return 1;

  else

    return fac*cal_factorial(fac-1);

}



int RM_64::cal_combination(int m, int r) //calculate c(m,r), r<=m, r stands for order

{

  return (cal_factorial(m)/(cal_factorial(r)*cal_factorial(m-r)));

}



void RM_64::set_n(int m)

{

	n = (int) pow(2, m);

}



int RM_64::get_n()

{

	return n;

}





void RM_64::set_k(int m, int r)//calculate k=c(m,0)+c(m,1)+...+c(m,r)

{

  int kk = 0;//kk is the sum of the combination

  for ( int i = 0; i <= r; i++)

    {

      kk = kk+cal_combination(m,i);

    }

  k = kk;

}



int RM_64::get_k()

{

	return k;

}





const int* RM_64::get_G()

{ 

  return &G[0][0];

}



void RM_64::set_G_matrix()

{

  int order, i, j, k, l;

  int row = 0, column = 0, from, mid, to = n;

  for (i = 0; i< n; i++) // the first row of G_matrix, which is all of 1

    G[0][i] = 1;

  

  row ++;

  while(row <= m && to > 1){

    while (column < n){//until the mth row

      from = 0; mid= to/2;

      while (from < mid) {

	G[row][column]=0;

				from ++; column ++;

      }

      while( mid < to) {

	G[row][column] = 1;//whether tempArrl can be replaced by the G[row][column]

				mid ++; column ++;

      }

    }

    column = 0;

    row ++; to = to/2;

  }



  //below is considered all the rows of the second order

  int _row =  row;

  for ( order = 2; order <= r; order++)

    {

      if ( order == 2)

	  {

	    while (_row < row + cal_combination(m, 2))

	    {

	      for (i=1; i < m+1; i++)

		{

		  for (j = i+1; j < m+1; j++)

		    {

		      multiply(G[_row], G[i], G[j], n);

		      _row++;

		    }

		  }

	    }

	  }

    if (order == 3)

	{

	  int temprow = _row;

	  while (_row < temprow + cal_combination(m, 3)) 

	    {

	      for ( i=1; i < m+1; i++)

		{

		  for (j= i+1; j < m+1; j++)

		    {

		      for (k= j+1; k < m+1; k++)

			{

			  multiply(G[_row], G[i], G[j], n);

			  multiply(G[_row], G[_row], G[k], n);

			  _row ++;

			}

		    }

		}

	    }

	}

    

    if (order == 4) 

      {

	int temprow = _row;

	while (_row < temprow + cal_combination(m, 4)) 

	  {

	    for ( i=1; i < m+1; i++)

	      {

		for (j= i+1; j < m+1; j++)

		  {

		    for (k= j+1; k < m+1; k++)

		      {

			for (l = k+1; l < m+1; l++)

			  {

			    multiply(G[_row], G[i], G[j], n);

			    multiply(G[_row], G[_row], G[k], n);

			    multiply(G[_row], G[_row], G[l], n);

			    _row ++;

			  }

		      }

		  }

	      }

	  }

      }

    }

}



void RM_64::multiply (int *out, int *v1, int *v2, int n)

{

  int i;

  for ( i=0; i < n; i++)

    {

      if((v1[i] == 1) && (v2[i] == 1))

		out[i] = 1;

      else

		out[i] = 0;

    }

}



void RM_64::display() const

{   cout << "Generator Matrix: " << endl;

	for(int i = 0; i < k; i++){

		for(int j = 0; j < n; j++)

		{   

		  cout  << G[i][j]<< " " ;

		}

		cout << endl;

	}

}



























































































⌨️ 快捷键说明

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