Esempio n. 1
0
 statement_interface *firebird_driver::make_statement(const shared_connection_ptr &conn) const
 {
     return new firebird_statement(conn, shared_transaction_ptr(make_transaction(conn)));
 }
Esempio n. 2
0
int main(int argc, char * argv[])
{
	int opt;
	while((opt = getopt(argc,argv,"c:d:f:w:i:o:")) != EOF)
	{
		switch(opt)
		{
		case 'c':
			CoverThreshold = atof(optarg);
			break;
		case 'd':
			DiscardThreshold = atof(optarg);
			break;
		case 'f':
			FThreshold = atof(optarg);
			break;
		case 'w':
			WThreshold = atof(optarg);
			break;
		case 'i':
			memcpy(ReadFileName,optarg,strlen(optarg));
			ReadFileName[strlen(optarg)] = '\0';
			break;
		case 'o':
			memcpy(WriteFileName,optarg,strlen(optarg));
			WriteFileName[strlen(optarg)] = '\0';
			break;
		}
	}
	/*if(argc == 2)
		WThreshold = atof(argv[1]);
	if(argc == 3)
	{
		WThreshold = atof(argv[1]);
		FThreshold = atof(argv[2]);
	}
	if(argc == 4)
	{
		WThreshold = atof(argv[1]);
		FThreshold = atof(argv[2]);
		DiscardThreshold = atof(argv[3]);
	}*/
	//initialize the queue
	MQueue = (Queue *)malloc(sizeof(Queue));
	MQueue->QnodeNum = 0;
	MQueue->StartQnode = (Qnode *)malloc(sizeof(Qnode));
	MQueue->EndQnode = (Qnode *)malloc(sizeof(Qnode));
	//
	MQueue->StartQnode->NextQnode = MQueue->EndQnode;//recording the relationship of the virsital start node and the virtual end node initially
	MQueue->EndQnode->PreviousQnode = MQueue->StartQnode;
	//
	MQueue->StartQnode->PreviousQnode = NULL;//no former node to the virtual start node
	MQueue->EndQnode->NextQnode = NULL;//node latter node to the virtual end node
	MQueue->StartQnode->QTnode = NULL;//NULL in the virtual start node
	MQueue->EndQnode->QTnode = NULL;//NULL in the virtual end node

	//judge m and n
	char str[10000];
	get_size(m);
	
	UsedTransactionNum = m;
	TransactionArray = (Transaction *)malloc(m*sizeof(Transaction));
	FILE * fr = fopen(ReadFileName,"r");
	for( int i = 0; i < m; i ++)
	{//transfer each line of the data into a Transaction, we regard that there are no more than 20000 letters each line
		fgets(str,10000,fr);
		make_transaction(TransactionArray,i,str);
	}
	fclose(fr);
	//till now, all the data in the file has been read into the memory
	//initial the structure of the Tree
	Tree * MTree;
	MTree = (Tree *)malloc(sizeof(MTree));
	MTree->TnodeNum = 0;
	MTree->Root = (Tnode *)malloc(sizeof(Tnode));
	MTree->Root->TTransactionNum = m;
	MTree->Root->TTransaction = (Transaction *)malloc(MTree->Root->TTransactionNum * sizeof(Transaction));//allocate memory for the Transaction in the root
	for( int i = 0; i < MTree->Root->TTransactionNum; i ++)
	{
		MTree->Root->TTransaction[i].ItemArray = TransactionArray[i].ItemArray;//copy all the elements in the TransactionArray into the MTree
		MTree->Root->TTransaction[i].PacketNum = TransactionArray[i].PacketNum;
	}
	MTree->Root->ChildTnodeArray = NULL;
	MTree->Root->ChildTnodeNum = 0;
	MTree->Root->FatherTnode = NULL;
	MTree->Root->NextTnode = NULL;
	MTree->Root->PreviousTnode = NULL;
	MTree->Root->TItem = 0;
	MTree->Root->TLevel = 0;
	MTree->Root->TSerialNum = 0;
	en_queue(MTree->Root);
	//while(MQueue->QnodeNum)
	//{
		//make_split(MTree,de_queue());
	//}
	int ThisLevelNum = 0;
	int LastTnodeLevel = 0; // the level of last Tnode, it is used for judging whether the level has changed
	int TillLastLevelFinishedNum = 0;
	int TillThisLevelFinishedNum = 0;
	//the below code is to input all the data into a file
	FILE * fw = fopen(WriteFileName,"w");
	Tnode * TmpTnode;
	//en_queue(MTree->Root);
	if( WThreshold < ((float)2)/MTree->Root->TTransactionNum)
		WThreshold = ((float)2)/MTree->Root->TTransactionNum - 0.01;
	while(MQueue->QnodeNum)
	{
		TmpTnode = de_queue();
		//fprintf(fw,"TSerialNum:%d UsedTransactionNum: %d ", TmpTnode->TSerialNum,  UsedTransactionNum);
	//if(TmpTnode->TSerialNum > 30)
	//	fprintf(fw,"Father %d ", TmpTnode->FatherTnode->TSerialNum);
	//	fprintf(stderr,"A\n");
		make_split(MTree,TmpTnode);// all the push are done inside make_split
	//fprintf(fw,"AUsedTNum: %d children;: %d\n",UsedTransactionNum,TmpTnode->ChildTnodeNum);
	//	fprintf(stderr,"%d\n",UsedTransactionNum);
	//	fprintf(stderr,"%d\n",MTree->Root->TTransactionNum);
	//	fprintf(stderr,"%f\n",CoverThreshold);
	//	 if(MQueue->QnodeNum == 0)
	//		fprintf(fw,"reach end\n");
		if((float)UsedTransactionNum / MTree->Root->TTransactionNum < CoverThreshold)
		{
	//	fprintf(stderr,"B\n");
			while(MQueue->QnodeNum)
			{
				TmpTnode = de_queue();
				fprintf(fw,"	Numof-Tran:%5d	\n",TmpTnode->TTransactionNum);
				for( int i = 0; i < TmpTnode->TLevel; i ++)
					fprintf(fw,"(@%d %d)%s %c ",TmpTnode->TItem[i].PacketSeqNum, TmpTnode->TItem[i].ByteSeqNum,TmpTnode->TItem[i].Pload,hex_asc(TmpTnode->TItem[i].Pload)==10?160:hex_asc(TmpTnode->TItem[i].Pload));
				fprintf(fw,"\n");
			}
			break;
		}
		if(TmpTnode->ChildTnodeNum)
			continue;
		fprintf(fw,"Numof-Tran:%5d	\n",TmpTnode->TTransactionNum);
		for( int i = 0; i < TmpTnode->TLevel; i ++)
			fprintf(fw,"(@%d %d)%s %c ",TmpTnode->TItem[i].PacketSeqNum, TmpTnode->TItem[i].ByteSeqNum,TmpTnode->TItem[i].Pload, hex_asc(TmpTnode->TItem[i].Pload)==10?160:hex_asc(TmpTnode->TItem[i].Pload));
		fprintf(fw,"\n");
	}
	//fprintf(fw,"TnodeNum: %d\n",MTree->TnodeNum);
	fprintf(fw,"\n\n%.4f%% of all the Transactions are covered by this feature\n", 100 * (float)UsedTransactionNum / MTree->Root->TTransactionNum);
	fprintf(fw,"Parameter: \n	FThreshold: %.2f;\n 	WThreshold: %.2f;\n 	DiscardThreshold: %.2f;\n 	CoverThreshold: %.2f;\n",FThreshold, WThreshold, DiscardThreshold, CoverThreshold);
	fclose(fw);
	fprintf(stdout,"success!\n");
	return 0;
}
Esempio n. 3
0
int main(int argc, char * argv[])
{
	int opt;
	int InitType;
	while((opt = getopt(argc,argv,"r:f:n:")) != EOF)
	{
		switch(opt)
		{
		case 'f':
			memcpy(FeatureFileName,optarg,strlen(optarg));
			FeatureFileName[strlen(optarg)] = '\0';
			break;
		case 'r':
			memcpy(ReadFileName,optarg,strlen(optarg));
			ReadFileName[strlen(optarg)] = '\0';
			break;
		case 'n':
			InitType = atoi(optarg);
			break;
		}
	}
	Feature * MyFeature;
	MyFeature = (Feature *)malloc(sizeof(Feature));
	MyFeature->FeatureNum = 0;
	char * str;
	str = new char[MEMSIZE];
	//char str[MEMSIZE];
	FILE * FeatureFr = fopen(FeatureFileName,"r");
	for(; fgets(str, MEMSIZE, FeatureFr);)
	{
		if(strlen(str) &&  str[0] == '(' )
			MyFeature->FeatureNum ++;
	}
	MyFeature->FeatureSize = new int[MyFeature->FeatureNum];
	MyFeature->FeatureItems = (PItem **)malloc(MyFeature->FeatureNum * sizeof(PItem *));
	rewind(FeatureFr);
	//judge m and n
	for( int i = 0; fgets(str, MEMSIZE, FeatureFr); )
	{
		if(strlen(str) && str[0] == '(')
		{
			MyFeature->FeatureSize[i] = 0;
			for( int j = 0; str[j]; j ++)
			{
				if(str[j] == '(')
				{
					MyFeature->FeatureSize[i] ++;
				}
			}
			i ++;
		}
	}
	rewind(FeatureFr);	
	for( int i = 0; i < MyFeature->FeatureNum; i ++)
	{
		MyFeature->FeatureItems[i] = (PItem *)malloc(MyFeature->FeatureSize[i] * sizeof(PItem));
	}
	for( int i = 0; fgets(str, MEMSIZE, FeatureFr); )
	{
		if(strlen(str) && str[0] == '(')
		{
			for( int j = 0, k = 0; str[j]; j ++)
			{
				if(str[j] == '(')
				{
					MyFeature->FeatureItems[i][k].ByteSeqNum = get_position(str + j + 2);
				}
				if(str[j] == ')')
				{
					MyFeature->FeatureItems[i][k].Pload[0] = str[j + 1];
					MyFeature->FeatureItems[i][k].Pload[1] = str[j + 2];
					MyFeature->FeatureItems[i][k].Pload[2] = '\0';
					k ++;
				}
			}
			i ++;
		}
	}
		
	fclose(FeatureFr);
	FILE * wfr = fopen(WriteFileName, "w");	
	Transaction * MyTransaction;
	MyTransaction = (Transaction *)malloc(sizeof(Transaction));
	FILE * fr = fopen(ReadFileName,"r");
	
	for( int i = 0; fgets(str,MEMSIZE,fr); i ++)
	{//transfer each line of the data into a Transaction, we regard that there are no more than 20000 letters each line
		fprintf(wfr,"%d %d ", InitType, InitType == atoi(str));
		if(str[1] == ' ')
			str = str + 2;
		else
			str = str + 3;
		make_transaction(MyTransaction,i,str);
		fprintf(wfr,"%d\n",check(MyFeature, MyTransaction));
	}
	fclose(fr);
	//till now, all the data in the file has been read into the memory
	//initial the structure of the Tree
	return 0;
}