当前位置: 首页>>代码示例>>C++>>正文


C++ BaseNode::Key方法代码示例

本文整理汇总了C++中BaseNode::Key方法的典型用法代码示例。如果您正苦于以下问题:C++ BaseNode::Key方法的具体用法?C++ BaseNode::Key怎么用?C++ BaseNode::Key使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BaseNode的用法示例。


在下文中一共展示了BaseNode::Key方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(void){
	int i, j, tmp;
	const int size = 10;
	vector<int>::iterator vi;
	Address a;
	TKey ans;
	BaseNode *p = NULL;
	int data[size] = {5, 2, 7, 1, 9, 4, 0, 6, 3, 8};
	vector<int> v(data, data+size);
	vector<int> vn;
	time_t t_start, t_end;

	// Initialize
	for(i = 0; i < BlockNum; i++)
		blockUsed[i] = false;
	for(i = 0; i < IndexNum; i++)
		indexRootBlockId[i] = -1;
	for(i = 0; i < IndexNum; i++)
		indexDataBlockId[i] = -1;
	for(i = 0; i < IndexNum; i++)
		indexType[i] = TYPE_INT;
	
	for(i = 0; i < DATA_NUM; i++)
		vn.push_back(i);
	srand((unsigned int)time(0));
	for(i = 0; i < DATA_NUM; i++){
		j = rand() % DATA_NUM;
		tmp = vn.at(j);
		vn.erase(vn.begin() + j);
		vn.push_back(tmp);
	}
	/*for(i = 0; i < DATA_NUM; i++){
		cout << vn.at(i) << ' ';
	}
	system("pause");
	return 0;*/

	// test
	try{
		cout << "----------------insert " << DATA_NUM << " numbers----------------------" << endl;
		time(&t_start);
		//for(i = 0; i < 15; i++){
		//for(i = DATA_NUM; i >= 0; i--){
		for(vi = vn.begin(); vi != vn.end(); vi++){
			i = *vi;
			if(!(i % (DATA_NUM / PRINT_NUM)))
				cout << "-------------insert " << i << "---------------" << endl;
			try{
				a = InsertIndex(0, 0, TKey(i));
			}
			catch(ErKeyNotFound &e){
				cout << e.what() << e.key() << endl;
			}
			catch(DbEr &e){
				cout << e.what() << endl;
			}
			//p = (BaseNode *)GetBlock(a.blockId);

			//cout << "Insert Data Block: " << a.blockId << endl;

			//p->data[a.offset] = i;

			//PrintIndex(GetRootBlockId(0), p);
			//PrintCatalog();
		}
		time(&t_end);
		cout << "Run time for insert " << DATA_NUM << " data: " << t_end - t_start << "s" << endl;
		//PrintData(0, p);
		//PrintIndex(GetRootBlockId(0), p);

		cout << "----------------query " << DATA_NUM << " numbers----------------------" << endl;
		time(&t_start);
		//for(i = 0; i <= DATA_NUM; i++){
		for(vi = vn.begin(); vi != vn.end(); vi++){
			i = *vi;
			if(!(i % (DATA_NUM / PRINT_NUM)))
				cout << "-------------query " << i << "----------------" << endl;
			try{
				a = FindIndex(0, 0, TKey(i));
				p = (BaseNode *)GetBlock(a.blockId);
				ans = TKey(p->Key(a.offset), p->type);
				if(ans.iKey != i){
					throw ErKeyNotFound(TKey(i));
				}
			}
			catch(ErKeyNotFound &e){
				cout << e.what() << e.key() << endl;
			}
			catch(DbEr &e){
				cout << e.what() << endl;
			}

			//PrintIndex(GetRootBlockId(0), p);
			//PrintCatalog();
		}
		time(&t_end);
		cout << "Run time for query " << DATA_NUM << " data: " << t_end - t_start << "s" << endl;
		PrintCatalog();

		cout << "----------------delete " << DATA_NUM << " numbers----------------------" << endl;
//.........这里部分代码省略.........
开发者ID:elff1,项目名称:myCodes,代码行数:101,代码来源:main.cpp


注:本文中的BaseNode::Key方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。