SwatDB
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
BlockHeapFileScanner Class Reference

#include <blockheapfilescanner.h>

Collaboration diagram for BlockHeapFileScanner:
Collaboration graph
[legend]

Public Member Functions

 BlockHeapFileScanner (HeapFile *file, std::uint32_t block_size)
 Constructor.
 
 ~BlockHeapFileScanner ()
 Destructor.
 
RecordId getNext (Record *record)
 Returns RecordId of the next Record in the HeapFile and initializes the given Record object to the data of the identified Record. Scans for records by iterating through the linked list of full pages, then the linked list of free pages in block size chunks.
 
bool nextBlock ()
 Increments to the next block of pages. Pins the first page of the block and sets beg_page to that page. Resets the block count.
 
void resetBlock ()
 Resets cur_page to the beginning of the current block. Uses beg_page.
 

Private Member Functions

bool _advancePage ()
 advances to the next page in the heapfile, accounting for cases of end of full and end of free.
 

Private Attributes

BufferManagerbuf_mgr
 
PageId cur_pid
 
HeapPagecur_page
 
PageId beg_pid
 
bool beg_full
 
std::uint32_t block_size
 
std::uint32_t block_count
 
HeapPageScannerscanner
 
HeapFilefile
 
bool end_of_full
 
bool end_of_free
 

Detailed Description

Block Scanner class for HeapFile. Scanner scans the given HeapFile object and returns the next RecordId in a given block and initiliazes the Record Data whenever getNext is called. Returns INVALID_RECORD_ID if it reaches the end of the file or block. Functionality for resetting to beginning of block and iterating to the next block given a size.

Constructor & Destructor Documentation

◆ BlockHeapFileScanner()

BlockHeapFileScanner::BlockHeapFileScanner ( HeapFile file,
std::uint32_t  block_size 
)

Constructor.

Precondition
Valid HeapFile* is provided as input.
Postcondition
HeapFile object is constructed with initialized data members. The cur_page is pinned if file is not empty.
Parameters
fileHeapFile object to be scanned.
std::uint32_tblock size

◆ ~BlockHeapFileScanner()

BlockHeapFileScanner::~BlockHeapFileScanner ( )

Destructor.

Precondition
If the end of the File has not been reached, cur_page is pinned.
Postcondition
If the end of the File has not been reached, cur_page is released.

Member Function Documentation

◆ _advancePage()

bool BlockHeapFileScanner::_advancePage ( )
private

advances to the next page in the heapfile, accounting for cases of end of full and end of free.

Precondition
block_count is changed according to the caller's needs.
Postcondition
cur_page and cur_pid have changed to the new page.
Returns
bool whether or not a page was found.

◆ getNext()

RecordId BlockHeapFileScanner::getNext ( Record record)

Returns RecordId of the next Record in the HeapFile and initializes the given Record object to the data of the identified Record. Scans for records by iterating through the linked list of full pages, then the linked list of free pages in block size chunks.

Precondition
None
Postcondition
RecordId of the next Record is returned and data of the given Record object is initialized to that of the Record identified by the RecordId. If there are no more records in the HeapFile, or the end of the block has been reached, INVALID_RECORD_ID is returned. cur_page is the Page that is being scanned and is pinned. Once the end of cur_page is reached, it is the next Page in the File is pinned (if there is next Page) and cur_page is unpinned. cur_pid and cur_page are updated accordingly. If the end of the File is reached, no Page is pinned by the BlockHeapFileScanner.
Returns
Next valid RecordId. INVALID_RECORD_ID if the end of the file is reached.

◆ nextBlock()

bool BlockHeapFileScanner::nextBlock ( )

Increments to the next block of pages. Pins the first page of the block and sets beg_page to that page. Resets the block count.

Precondition
the end of the previous block has been reached, and the user wants to iterate to the next block of pages
Postcondition
the first page of the next block is pinned, and the beg_page state is updated accordingly. The block count is reset to 0.
Returns
bool. True if next block is valid and false if end of file has been reached.

◆ resetBlock()

void BlockHeapFileScanner::resetBlock ( )

Resets cur_page to the beginning of the current block. Uses beg_page.

Precondition
Reached the end of the block
Postcondition
cur_page is reset to beg_page

Member Data Documentation

◆ beg_full

bool BlockHeapFileScanner::beg_full
private

bool that keeps track of whether beg_page is on the full list or not This flag is useful for keeping track of whether the block spans the full list and the free list. In this case, reset block will need to know whether or not to reset the end_of_full flag to false.

◆ beg_pid

PageId BlockHeapFileScanner::beg_pid
private

PageId that references the beginning page of the block

◆ block_count

std::uint32_t BlockHeapFileScanner::block_count
private

Current iteration of block. Starting from 1, keeps track of how many pages have been scanned since the beginning of the block, thus indicating the number page the scanner is on from the block start.

◆ block_size

std::uint32_t BlockHeapFileScanner::block_size
private

Size of the block.

◆ buf_mgr

BufferManager* BlockHeapFileScanner::buf_mgr
private

Pointer to the BufferManager of SwatDB (for retrieving/pinning pages).

◆ cur_page

HeapPage* BlockHeapFileScanner::cur_page
private

HeapPage object that contains the latest Record scanned.

◆ cur_pid

PageId BlockHeapFileScanner::cur_pid
private

PageId of the Page that contains the latest Record scanned.

◆ end_of_free

bool BlockHeapFileScanner::end_of_free
private

bool indicating whether the end of the free pages list has been reached in the scan.

◆ end_of_full

bool BlockHeapFileScanner::end_of_full
private

bool indicating whether the end of the full pages list has been reached in the scan.

◆ file

HeapFile* BlockHeapFileScanner::file
private

Pointer to the HeapFile to be scanned.

◆ scanner

HeapPageScanner* BlockHeapFileScanner::scanner
private

HeapPageScanner object pointer for scanning through individual HeapPages.


The documentation for this class was generated from the following file: