一、按照相似项(一)的思路,采用C++来计算最小哈希签名矩阵。
代码如下:
#include <iostream>
using namespace std;
int matrix[5][4] = {
{1,0,0,1},
{0,0,1,0},
{0,1,0,1},
{1,0,1,1},
{0,0,1,0}
};
int SIG[2][4];
void initSIG()
{
for(int i=0;i<2;i++)
for(int j=0;j<4;j++)
SIG[i][j]=INT_MAX;
}
template<int C,int map[][C]>
void printM(int row)
{
for(int i = 0;i<row;i++)
{
for(int j=0;j<C;j++)
{
cout<<map[i][j]<<"\t";
}
cout<<endl;
}
cout<<endl;
}
int h1(int r)
{
return (r+1)%5;
}
int h2(int r)
{
return (3*r+1)%5;
}
//如何设置由函数作为数组元素的数组
int (*hashf[2])(int);
void inithash()
{
hashf[0]=h1;
hashf[1]=h2;
}
/*M=4,N=2,R=5*/
void minHash(int M, int N, int R)
{
for(int r=0;r<R;r++)
{
for(int m=0;m<M;m++)//per row