HFPage Class Reference

#include <HFPage.h>

List of all members.


Detailed Description

Heap file page.

This is a wrapper around a traditional Page that adds the appropriate struture to it.

Author:
Dave Musicant, with considerable material reused from the UW-Madison Minibase project


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.


Constructor & Destructor Documentation

HFPage::HFPage ( Page page  ) 

Creates a heap file page object by wrapping around a page object already provided.

Parameters:
page pointer to the page to be wrapped.


Member Function Documentation

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.)

Parameters:
rid the RID to be deleted.
Returns:
true if successful, false if the rid is actually not found on the page.

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.

Returns:
true if the page is empty, false otherwise.

RID HFPage::firstRecord (  ) 

Returns RID of first record on page.

Returns:
the RID of the first record on the page. Returns an RID with pageId == INVALID_PAGE if the file is empty.

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.

Returns:
the amount of available space in bytes

int HFPage::getNextPageId (  ) 

Gets the next page id.

Returns:
the next page id.

int HFPage::getPageId (  ) 

Gets the page id.

Returns:
the page id.

int HFPage::getPrevPageId (  ) 

Gets the previous page id.

Returns:
the previous page id.

void HFPage::getRecord ( RID  rid,
char  record[],
int &  recLen 
)

Returns the record associated with an RID.

Parameters:
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
Exceptions:
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.

Parameters:
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
Returns:
the RID of the new record
Exceptions:
PageFullException if there is not enough room for the record on the page.

RID HFPage::nextRecord ( RID  curRid  ) 

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.

Parameters:
curRid an RID
Returns:
the RID immediately following curRid. Returns an RID with pageId == INVALID_PAGE if no next record exists.
Exceptions:
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.

Parameters:
pageId the next page id.

void HFPage::setPageId ( int  pageId  ) 

Sets the page id.

Parameters:
pageId the new page id.

void HFPage::setPrevPageId ( int  pageId  ) 

Sets the previous page id.

Parameters:
pageId the previous page id.


Generated on Thu Aug 30 08:39:22 2007 for Minibase by  doxygen 1.4.7