#include <HFPage.h>
This is a wrapper around a traditional Page that adds the appropriate struture to it.
Public Member Functions | |
HFPage (Page *page) | |
Creates a heap file page object by wrapping around a page object already provided. | |
void | init () |
Initializes values on the heap file page as necessary. | |
void | setPageId (int pageId) |
Sets the page id. | |
int | getPageId () |
Gets the page id. | |
void | setNextPageId (int pageId) |
Sets the next page id. | |
int | getNextPageId () |
Gets the next page id. | |
void | setPrevPageId (int pageId) |
Sets the previous page id. | |
int | getPrevPageId () |
Gets the previous page id. | |
int | getAvailableSpace () |
Determines how much space is actually available on the page, which depends on whether or not a new slot in the slot array is needed. | |
void | dumpPage () |
Dumps out to the screen the id for this page, as well as the ids for the next and previous pages. | |
RID | insertRecord (char record[], int recLen) |
Inserts a new record onto the page. | |
bool | deleteRecord (RID rid) |
Deletes the record with the given RID from the page, compacting the hole created. | |
RID | firstRecord () |
Returns RID of first record on page. | |
RID | nextRecord (RID curRid) |
Returns RID of next record on the page, where "next on the page" means "next in the slot array. | |
void | getRecord (RID rid, char record[], int &recLen) |
Returns the record associated with an RID. | |
bool | empty () |
Whether or not the page is empty. | |
Static Public Attributes | |
static const int | INVALID_PAGE = -1 |
Value to use for an invalid page id. | |
static const int | INVALID_SLOT = -1 |
Value to use for an invalid slot. |
HFPage::HFPage | ( | Page * | page | ) |
Creates a heap file page object by wrapping around a page object already provided.
page | pointer to the page to be wrapped. |
bool HFPage::deleteRecord | ( | RID | rid | ) |
Deletes the record with the given RID from the page, compacting the hole created.
Compacting the hole, in turn, requires that all the offsets (in the slot array) of all records after the hole be adjusted by the size of the hole, because you are moving these records to "fill" the hole. You should leave a "hole" in the slot array for the slot which pointed to the deleted record, if necessary, to make sure that the rids of the remaining records do not change. The slot array should be compacted only if the record corresponding to the last slot is being deleted. (memmove, not memcpy, is used underneath since the space may overlap.)
rid | the RID to be deleted. |
void HFPage::dumpPage | ( | ) |
Dumps out to the screen the id for this page, as well as the ids for the next and previous pages.
It also displays the slot array to the screen in a readable dashion. (This method merely exists for debugging and testing purposes.
bool HFPage::empty | ( | ) |
Whether or not the page is empty.
RID HFPage::firstRecord | ( | ) |
int HFPage::getAvailableSpace | ( | ) |
Determines how much space is actually available on the page, which depends on whether or not a new slot in the slot array is needed.
If a new spot in the slot array is needed, then the amount of available space has to take this into consideration.
int HFPage::getNextPageId | ( | ) |
Gets the next page id.
int HFPage::getPageId | ( | ) |
Gets the page id.
int HFPage::getPrevPageId | ( | ) |
Gets the previous page id.
void HFPage::getRecord | ( | RID | rid, | |
char | record[], | |||
int & | recLen | |||
) |
Returns the record associated with an RID.
rid | the rid of interest | |
record | a pre-existing array for the record to be copied into | |
recLen | where the length of the record is copied into |
BadPageIdException | if the page id within curRid is invalid | |
BadSlotIdException | if the slot id within curRid is invalid |
void HFPage::init | ( | ) |
Initializes values on the heap file page as necessary.
This is separated out from the constructor since it actually modifies the page at hand, where as the constructor simply sets up the mechanism.
RID HFPage::insertRecord | ( | char | record[], | |
int | recLen | |||
) |
Inserts a new record onto the page.
record | the record to be inserted. A copy of the data is placed on the page. | |
recLen | the length of the record to be inserted |
PageFullException | if there is not enough room for the record on the page. |
Returns RID of next record on the page, where "next on the page" means "next in the slot array.
" Remember that some slots may be empty, so you should skip over these.
curRid | an RID |
BadPageIdException | if the page id within curRid is invalid | |
BadSlotIdException | if the slot id within curRid is invalid |
void HFPage::setNextPageId | ( | int | pageId | ) |
Sets the next page id.
pageId | the next page id. |
void HFPage::setPageId | ( | int | pageId | ) |
Sets the page id.
pageId | the new page id. |
void HFPage::setPrevPageId | ( | int | pageId | ) |
Sets the previous page id.
pageId | the previous page id. |