本文整理汇总了C++中Scan::MoveTo方法的典型用法代码示例。如果您正苦于以下问题:C++ Scan::MoveTo方法的具体用法?C++ Scan::MoveTo怎么用?C++ Scan::MoveTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scan
的用法示例。
在下文中一共展示了Scan::MoveTo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Execute
//---------------------------------------------------------------
// BlockNestedLoop::Execute
//
// Input: left - The left relation to join.
// right - The right relation to join.
// Output: out - The relation to hold the ouptut.
// Return: OK if join completed succesfully. FAIL otherwise.
//
// Purpose: Performs a block nested loops join on the specified relations.
// You can find a specification of this algorithm on page 455. You should
// choose the smaller of the two relations to be the outer relation, but you
// should make sure to concatenate the tuples in order <left, right> when
// producing output. The block size can be specified in the constructor,
// and is stored in the variable blockSize.
//---------------------------------------------------------------
Status BlockNestedLoops::Execute(JoinSpec& left, JoinSpec& right, JoinSpec& out) {
JoinMethod::Execute(left, right, out);
Status s;
HeapFile* tmpHeap = new HeapFile(NULL, s);
if (s != OK) {
std::cout << "Creating new Heap File Failed" << std::endl;
return FAIL;
}
Scan * leftScan = left.file->OpenScan(s);
if (s != OK) {
std::cout << "Open scan left failed" << std::endl;
return FAIL;
}
Scan * rightScan = right.file->OpenScan(s);
if (s != OK) {
std::cout << "Open scan left failed" << std::endl;
return FAIL;
}
RecordID leftRid, rightRid, rightFirstRid, outRid;
// array to hold the "block" in memory
char* blockArray = new char[left.recLen * blockSize];
int blockArraySize = 0; // size in case of half full block
int* leftCurrRec = (int *)blockArray;
int* leftRec = new int[left.numOfAttr];
int* rightRec = new int[right.numOfAttr];
int leftRecLen = left.recLen;
int rightRecLen = right.recLen;
char* newRec = new char[left.recLen + right.recLen];
rightFirstRid = rightScan->currRid;
Status st = OK;
while (true) {
// fill the block with as many records as possible
if (blockArraySize < blockSize) {
st = leftScan->GetNext(leftRid, (char *)leftRec, leftRecLen);
if (st != DONE) {
memcpy(blockArray + left.recLen * blockArraySize, leftRec, left.recLen);
blockArraySize++;
continue;
}
}
// scan through the right, and scan the block in memory for joins
while (rightScan->GetNext(rightRid, (char *)rightRec, rightRecLen) != DONE) {
for (int j = 0; j < blockSize; j++) {
if (j >= blockArraySize) {
break;
}
leftCurrRec = (int *) (blockArray + left.recLen * j);
if (leftCurrRec[left.joinAttr] == rightRec[right.joinAttr]) {
MakeNewRecord(newRec, (char *)leftCurrRec, (char *)rightRec, left, right);
tmpHeap->InsertRecord(newRec, left.recLen + right.recLen, outRid);
}
}
}
rightScan->MoveTo(rightFirstRid);
blockArraySize = 0;
if (st == DONE) {
break;
}
}
out.file = tmpHeap;
//std::cout << "NUM BNL: " << tmpHeap->GetNumOfRecords() << std::endl;
delete leftScan;
delete rightScan;
delete blockArray;
delete leftRec;
delete rightRec;
delete newRec;
return OK;
}