本文整理汇总了C++中Page::clearPage方法的典型用法代码示例。如果您正苦于以下问题:C++ Page::clearPage方法的具体用法?C++ Page::clearPage怎么用?C++ Page::clearPage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Page
的用法示例。
在下文中一共展示了Page::clearPage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: megrePagesToFile
void pagesManager::megrePagesToFile( int begin, int end, FILE* tempFptr ) {
//get last Page for output
Page *lastPage = &pages[ end + 1 ];
lastPage->clearPage();
//keep track of pages
int *offsets = new int[end - begin + 1];
memset( offsets, 0, ( end - begin + 1 ) * 4 );
while ( true ) { //when the pages have not been read
int min = -1; //find the minimize of the first entry of pages
bool first = true;
for ( int i = begin ; i <= end; i++ ) {
//printPage( pages[i].getData() );
if ( offsets[ i - begin ] < pages[i].getOffset() ) { //if this page is not been read at end
if ( first ) { //init the min
first = false;
min = i;
} else if( compare( pages[i].getData() + offsets[i-begin],
pages[min].getData() + offsets[min-begin] ) < 0 ) {
min = i;
}
}
} //for loop end, min save the value of the pageIndex of min
while ( !lastPage->insertDataToPage( pages[min].getData() + offsets[min-begin], 8 ) ) { //insert the min value to the output page
//if insert fail
//write page to file
lastPage->writePageToFile( tempFptr );
lastPage->clearPage();
}
offsets[ min - begin ] += 8; //next entry
//exam if all pages has been read
int i;
for ( i = begin ; i <= end; i++ ) {
if ( offsets[ i - begin ] < pages[i].getOffset() ) { //if a page is not at the end
break;
}
}
if ( i == end + 1 ) { //if all pages has been read, break the loop
break;
}
}
//write remain page
lastPage->writePageToFile( tempFptr );
clearPages( begin, end + 1 );
}
示例2: megreFilesToFile
void pagesManager::megreFilesToFile( FILE **tempFileArray, int tempFileCount, FILE *outputFptr ) {
//read pages from files
for ( int i = 0; i < tempFileCount; i++ ) {
readFileToPageAtIndex( tempFileArray[i], i );
}
//last page for output
Page *outputPage = &pages[tempFileCount];
outputPage->clearPage();
int readCount = 0; //count the number of files have been read
int *offsets = new int[tempFileCount]; //keep track of pages
memset( offsets, 0, tempFileCount * sizeof(int) );
bool *fileHaveRead = new bool[tempFileCount];
memset( fileHaveRead, false, tempFileCount );
int min = -1;
while ( readCount < tempFileCount ) {
/* megre pages */
//find the minimize of the pages
min = -1;
bool first = true;
for ( int i = 0; i < tempFileCount; i++ ) {
if ( offsets[i] >= pages[i].getOffset() && fileHaveRead[i] ) {
//if this page is end and the file is end
//it can not be the minimize of the pages
continue;
}
if ( first ) {
first = false;
min = i;
} else if ( compare( pages[i].getData() + offsets[i],
pages[min].getData() + offsets[min] ) < 0 ) {
min = i;
}
}
//isert the minimize to output page
while ( !outputPage->insertDataToPage( pages[min].getData() + offsets[min], 8 ) ) {
outputPage->writePageToFile( outputFptr );
outputPage->clearPage();
}
offsets[min] += 8;
//if pages[min] have been read
if ( offsets[min] >= pages[min].getOffset() ) {
//read next page
readFileToPageAtIndex( tempFileArray[min], min );
offsets[min] = 0;
if ( feof( tempFileArray[min] ) ) { //if file have been read
readCount++;
fileHaveRead[min] = true;
}
}
}
//write remain pages
for ( int i = 0; i < tempFileCount; i++ ) {
while ( offsets[i] < pages[i].getOffset() ) {
while ( !outputPage->insertDataToPage( pages[i].getData() + offsets[i], 8 ) ) {
outputPage->writePageToFile( outputFptr );
outputPage->clearPage();
}
offsets[i] += 8;
}
}
outputPage->writePageToFile( outputFptr );
outputPage->clearPage();
delete [] offsets;
delete [] fileHaveRead;
}