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

📄 boolobj.c

📁 eXtremeDB数据库在Linux平台下的使用源码。内含多个示例程序
💻 C
字号:
#include <stdio.h>#include <stdlib.h>#include <string.h>#include "simple.h"#ifdef _BOOL_OBJECT_TEST_void prnObject(AreaCodeBool * areaCode){	MCO_RET                 rc = 0;	char					pstr[10];	uint4					val;	uint2 sz;		rc = AreaCodeBool_areaCode_size( areaCode, &sz);	if ( rc != MCO_S_OK ) {		printf( "\n\terror:%d", rc );	}	val=0;	rc = AreaCodeBool_areaCode_get_range( areaCode,0,sz,(char*)&val);	if ( rc != MCO_S_OK ) {		printf( "\n\terror:%d", rc );	}	rc = AreaCodeBool_strAreaCode_get( areaCode,pstr,10);	if ( rc != MCO_S_OK ) {		printf( "\n\terror:%d", rc );	}		printf("<%x,%s>\n",val,pstr);}void doListing( mco_db_h db ) {	MCO_RET                 rc = 0;	mco_cursor_t            csr;	mco_trans_h             trn;	AreaCodeBool            areaCode;		printf( "Data listing:\n" );		mco_trans_start( db, MCO_READ_WRITE, MCO_TRANS_FOREGROUND, &trn );		/* initialize cursor */	rc = AreaCodeBool_IareaCode_index_cursor( trn, &csr );		for	(		rc = mco_cursor_first(trn, &csr);	rc == MCO_S_OK;	rc = mco_cursor_next(trn, &csr)		)	{		rc = AreaCodeBool_from_cursor( trn, &csr, &areaCode );		if ( rc != MCO_S_OK ) {			printf( "\n\terror:%d", rc );			break;		}				prnObject( &areaCode );	}			mco_trans_commit( trn );		return;}int calcBitLen(uint4 val){	int i,blen=31;	i=blen;	while (i)	{		if ((val>>i)&1) break;		i--;	} 	i=((i+3+1)/4)*4;  	if (!i) return 4;  	else return i;//  	if (!i) return 1;//  	else return i+1;	return 32;}int AddRecord(mco_trans_h t,uint4 val, const char* pstr){	MCO_RET rc;	AreaCodeBool areaCode;	int sz;	rc = AreaCodeBool_new(t, &areaCode);	if ( rc != MCO_S_OK ) return rc;	rc = AreaCodeBool_strAreaCode_put(&areaCode, pstr,(uint2)( strlen(pstr)+1));	if ( rc != MCO_S_OK ) return rc;	sz=calcBitLen(val);	if ((val&(~(((0xffffffff)>>sz)<<sz)))!=val)	{		//getchar();	}	rc = AreaCodeBool_areaCode_alloc(&areaCode,(uint2)sz);	if ( rc != MCO_S_OK ) return rc;	rc = AreaCodeBool_areaCode_put_range(&areaCode,0,(uint2)sz,(char*)&val);	if ( rc != MCO_S_OK ) return rc;	return MCO_S_OK;}int createDatabase(mco_db_h db){	MCO_RET                 rc = 0;	mco_trans_h             t;			mco_trans_start( db, MCO_READ_WRITE, MCO_TRANS_FOREGROUND, &t );	AddRecord(t,0x1,"ATT");	AddRecord(t,0x20,"BCC");	AddRecord(t,0x25,"TNT");	AddRecord(t,0x3,"ANC");	AddRecord(t,0x355,"NCC");	AddRecord(t,0x355,"UDC");	AddRecord(t,0x45,"WTC");	AddRecord(t,0x454,"FCC");	AddRecord(t,0x5,"ABB");	AddRecord(t,0x51,"DDA");	AddRecord(t,0x51,"FIY");	AddRecord(t,0x513,"ASD");	AddRecord(t,0x515,"ASH");	AddRecord(t,0x5183,"ASW");	AddRecord(t,0x525,"ASY");	AddRecord(t,0x6,"YUI");	AddRecord(t,0x64,"KEW");	AddRecord(t,0x66,"WER");	AddRecord(t,0x668,"VBR");	AddRecord(t,0x668,"MPP");	AddRecord(t,0x668,"FCA");	AddRecord(t,0x6689,"FCU");	AddRecord(t,0x699,"FCH");	AddRecord(t,0x6683,"FCL");	AddRecord(t,0x6685,"FCD");	AddRecord(t,0x6687,"FCA");	AddRecord(t,0x7,"MNM");	AddRecord(t,0x7,"MGM");	AddRecord(t,0x79,"MSM");	AddRecord(t,0x795,"EAE");	AddRecord(t,0x81,"YUI");	AddRecord(t,0x84,"WWW");	AddRecord(t,0x849,"OLA");	AddRecord(t,0x9,"GEA");	AddRecord(t,0x99,"YTR");	AddRecord(t,0x99,"IUI");	AddRecord(t,0x988,"JHJ");	AddRecord(t,0x988,"DFD");		rc = mco_trans_commit( t );	if ( rc != MCO_S_OK )		printf("Commit error %d !\n",rc);	return rc;}void searchExact( mco_db_h db, uint4  AreaCode ){	MCO_RET                 rc = 0;	mco_trans_h             trn;	AreaCodeBool            areaCode;	mco_cursor_t            csr;	uint2 sz;			mco_trans_start( db, MCO_READ_ONLY, MCO_TRANS_FOREGROUND, &trn );		rc = AreaCodeBool_IareaCode_index_cursor( trn, &csr );	sz = calcBitLen(AreaCode);	rc = AreaCodeBool_IareaCode_exact_match(trn, &csr,(char*)&AreaCode, sz);	if ( rc == MCO_S_OK )	{		printf("Found ExactMatch for key %x:\n",AreaCode);		while (rc == MCO_S_OK)		{			rc = AreaCodeBool_from_cursor( trn, &csr, &areaCode );			if ( rc != MCO_S_OK ) {				printf( "\n\terror:%d", rc );				break;			}			prnObject(&areaCode);						rc = mco_cursor_next(trn,&csr);			if ( rc == MCO_S_OK )			{				int rsl;				rc = AreaCodeBool_IareaCode_compare(trn,&csr,(char*)&AreaCode,sz,&rsl);				if ( rc != MCO_S_OK ) {					printf( "\n\terror:%d", rc );					break;				}				if (rsl) break;							}		}			}else printf("Not found ExactMatch for key %x:\n",AreaCode);			rc = mco_trans_commit( trn );		if ( rc != MCO_S_OK )		printf("Commit error %d !\n",rc);	}void searchPrefix( mco_db_h db, uint4 AreaCodePref ){	MCO_RET                 rc = 0;	mco_trans_h             trn;	AreaCodeBool            areaCode;	mco_cursor_t            csr;	uint2 sz;	int						longestR = 0;	char					cycle = 0;	uint4					key = AreaCodePref;			mco_trans_start( db, MCO_READ_ONLY, MCO_TRANS_FOREGROUND, &trn );		rc = AreaCodeBool_IareaCode_index_cursor( trn, &csr );	sz = calcBitLen(AreaCodePref);	rc = AreaCodeBool_IareaCode_prefix_match(trn, &csr,(char*)&key, sz);	if ( rc == MCO_S_OK )	{		int found = 0;				while (rc == MCO_S_OK)		{			int rsl;			rc = AreaCodeBool_IareaCode_compare(trn,&csr,(char*)&key,sz,&rsl);			if ( rc != MCO_S_OK ) {				printf( "\n\terror:%d", rc );				break;			}			if (rsl)			{				if (rsl<=-4) goto lNext;				else break;			}						if (!found)				printf("Found PrefixMatch for key %x:\n",AreaCodePref);			found = 1;						rc = AreaCodeBool_from_cursor( trn, &csr, &areaCode );			if ( rc != MCO_S_OK ) {				printf( "\n\terror:%d", rc );				break;			}			prnObject(&areaCode);lNext:					rc = mco_cursor_prev(trn,&csr);		}		if (!found) printf("Not found PrefixMatch for key %x:\n",AreaCodePref);			}else printf("Not found PrefixMatch for key %x:\n",AreaCodePref);			rc = mco_trans_commit( trn );		if ( rc != MCO_S_OK )		printf("Commit error %d !\n",rc);	}void searchLongest( mco_db_h db, uint4 AreaCodePref ){	MCO_RET                 rc = 0;	mco_trans_h             trn;	AreaCodeBool            areaCode;	mco_cursor_t            csr;	uint2 sz;	int						longestR = 0;	char					cycle = 0;	uint4					key = AreaCodePref;	mco_trans_start( db, MCO_READ_ONLY, MCO_TRANS_FOREGROUND, &trn );		rc = AreaCodeBool_IareaCode_index_cursor( trn, &csr );	sz = calcBitLen(AreaCodePref);	rc = AreaCodeBool_IareaCode_longest_match(trn, &csr, (char*)&key, sz);	if ( rc == MCO_S_OK )	{		int found = 0;				while (rc == MCO_S_OK)		{			int rsl;			rc = AreaCodeBool_IareaCode_compare(trn,&csr,(char*)&key,sz,&rsl);			if ( rc != MCO_S_OK ) {				printf( "\n\terror:%d", rc );				break;			}			if (rsl) break;			if (!found)				printf("Found LongestMatch for key %x:\n",AreaCodePref);			found = 1;						rc = AreaCodeBool_from_cursor( trn, &csr, &areaCode );			if ( rc != MCO_S_OK ) {				printf( "\n\terror:%d", rc );				break;			}			prnObject(&areaCode);						rc = mco_cursor_prev(trn,&csr);		}		if (!found) printf("Not found LongestMatch for key %x:\n",AreaCodePref);			}else printf("Not found LongestMatch for key %x:\n",AreaCodePref);			rc = mco_trans_commit( trn );		if ( rc != MCO_S_OK )		printf("Commit error %d !\n",rc);	}void doGoogle( mco_db_h db ){		//////////////////////////////////////////////////////////////////////////	// Exact search		printf("\n//////////////////////////////////////\n");	printf("ExactMatch function demonstration:\n\n");		searchExact( db, 0x1);	searchExact( db, 0x55);	searchExact( db, 0x5);	searchExact( db, 0x51);	searchExact( db, 0x6);	searchExact( db, 0x7);		//////////////////////////////////////////////////////////////////////////	// prefixSearch		printf("\n//////////////////////////////////////\n");	printf("PrefixMatch function demonstration:\n\n");		searchPrefix( db, 0x190);	searchPrefix( db, 0x55);	searchPrefix( db, 0x589);	searchPrefix( db, 0x51);	searchPrefix( db, 0x511);	searchPrefix( db, 0x5189);	searchPrefix( db, 0x668889);	searchPrefix( db, 0x698889);	searchPrefix( db, 0x71111111);			//////////////////////////////////////////////////////////////////////////	// longestSearch		printf("\n//////////////////////////////////////\n");	printf("LongestMatch function demonstration:\n\n");		searchLongest( db, 0x190);	searchLongest( db, 0x55);	searchLongest( db, 0x589);	searchLongest( db, 0x5189);	searchLongest( db, 0x51);	searchLongest( db, 0x511);	searchLongest( db, 0x668889);	searchLongest( db, 0x698889);	searchLongest( db, 0x71111111);		printf("\n" );}#endif //_BOOL_OBJECT_TEST_

⌨️ 快捷键说明

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