本文整理汇总了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;
//.........这里部分代码省略.........