SwatDB
Public Member Functions | Private Member Functions | Friends | List of all members
HeapPage Class Reference

#include <heappage.h>

Inheritance diagram for HeapPage:
Inheritance graph
[legend]
Collaboration diagram for HeapPage:
Collaboration graph
[legend]

Public Member Functions

 HeapPage ()=delete
 Constructor. More...
 
 ~HeapPage ()
 
void initializeHeader ()
 Initializes header information after the Page is allocated. More...
 
void setNext (PageNum page_num)
 Sets next_page to the given PageNum. More...
 
void setPrev (PageNum page_num)
 Set prev_page to the given PageNum. More...
 
PageNum getNext ()
 Getter for next_page. More...
 
PageNum getPrev ()
 Getter for prev_page. More...
 
std::uint32_t getFreeSpace ()
 Getter for the amount of free space free on the Page. More...
 
bool isFull ()
 bool function indicating whether the Page is full. More...
 
bool isEmpty ()
 bool function indicating whether the Page is empty. More...
 
SlotId insertRecord (Data *record_data)
 Inserts given record data to the Page. More...
 
void getRecord (SlotId slot_id, Data *data)
 Gets the record identified by SlotId. More...
 
void deleteRecord (SlotId slot_id)
 Deletes Record identified by SlotId. More...
 
void updateRecord (SlotId slot_id, Data *record_data)
 Updates Record identified by SlotId. More...
 
HeapPageHeader getHeader ()
 THIS METHOD IS FOR DEBUGGING ONLY. Returns this HeapPage's header information.
 
SlotInfo getSlotInfo (SlotId slot_id)
 THIS METHOD IS FOR DEBUGGING ONLY. Returns SlotInfo struct of the given SlotId.
 
std::uint32_t getInvalidNum ()
 THIS METHOD IS FOR DEBUGGING ONLY. Returns number of invalid slots in the HeapPage.
 
void printHeapPageState ()
 THIS METHOD IS FOR DEBUGGING ONLY. Prints the current state of the HeapPage.
 
- Public Member Functions inherited from Page
 Page ()
 Constructor.
 
 ~Page ()
 Destructor.
 
char * getData ()
 Get function for the data char array. More...
 

Private Member Functions

HeapPageHeader_getPageHeader ()
 Getter for the Page header. More...
 
SlotInfo_getSlotDirectory ()
 Return pointer to the where slot directory begins (first SlotInfo) More...
 

Friends

class HeapPageScanner
 

Additional Inherited Members

- Protected Attributes inherited from Page
char data [PAGE_SIZE]
 char array that stores the page data. Derived classes could map appropriate structures on it.
 

Detailed Description

SwatDB HeapPage Class. HeapPage inherits from base Page class and instantiates heap page, collection of which, form HeapFile.

Constructor & Destructor Documentation

◆ HeapPage()

HeapPage::HeapPage ( )
delete

Constructor.

Constructor should never be called. It should be always the case that base class Page constructor is called by the BufferManager when initializing bufferpool. HeapPage Pointer is casted to whatever Page pointer returned by the BufferManager

◆ ~HeapPage()

HeapPage::~HeapPage ( )
inline

Destructor

Member Function Documentation

◆ _getPageHeader()

HeapPageHeader* HeapPage::_getPageHeader ( )
private

Getter for the Page header.

Returns
Pointer to the HeapPageHeader of the Page (beginning of data array).

◆ _getSlotDirectory()

SlotInfo* HeapPage::_getSlotDirectory ( )
private

Return pointer to the where slot directory begins (first SlotInfo)

Precondition
None
Postcondition
Pointer to first SlotInfo is returned.
Parameters
slot_idSlotId of SlotInfo* that is returned.
Returns
Pointer to the first SlotInfo in slot directory.

◆ deleteRecord()

void HeapPage::deleteRecord ( SlotId  slot_id)

Deletes Record identified by SlotId.

Precondition
A valid SlotId is provided as input
Postcondition
The record in that slot is removed from the page, and its slot directory entry is freed. The remaining records on the page are compacted at the end of the page. Page meta data and slot directory entries are updated to reflect the deletion this record. The total amount of freespace on the page increases. The slot directory may shrink by one or more SlotInfo entries as a result of this call.
Parameters
slot_idSlotId of the Record to be deleted.
Exceptions
InvalidSlotIdHeapPageIf SlotId is invalid (SlotId is out of range or SlotInfo of the given SlotId has INVALID_SLOT_OFFSET).

◆ getFreeSpace()

std::uint32_t HeapPage::getFreeSpace ( )

Getter for the amount of free space free on the Page.

Precondition
None.
Postcondition
The amount of free space in bytes on the Page is returned. If there is no free slot, sizeof(SlotInfo) is subtracted from the free space returned (accounting extra space occupied if new slot is allocated). If free space is less than sizeof(SlotInfo), 0 is returned.
Returns
Amount of free space in bytes on the Page.

◆ getNext()

PageNum HeapPage::getNext ( )

Getter for next_page.

Precondition
None.
Postcondition
next_page of the page header is returned.
Returns
PageNum of the next Page.

◆ getPrev()

PageNum HeapPage::getPrev ( )

Getter for prev_page.

Precondition
None.
Postcondition
prev_page of the Page header is returned.
Returns
PageNum of the previous Page.

◆ getRecord()

void HeapPage::getRecord ( SlotId  slot_id,
Data data 
)

Gets the record identified by SlotId.

*

Precondition
A valid SlotId is provided as input and a valid Data with capacity that is greater than maximum size of any Record stored in the Page is passed.
Postcondition
The data field of record_data contains a copy of the requsted record data stored in the Page, and the size the size of Data object is set to the number of bytes of the record.
Parameters
slot_idSlotId of the Record to be retrieved
Exceptions
InvalidSlotIdHeapPageIf SlotId is out of range or SlotInfo of the given SlotId has INVALID_SLOT_OFFSET.

◆ initializeHeader()

void HeapPage::initializeHeader ( )

Initializes header information after the Page is allocated.

Precondition
None
Postcondition
Page header is initialized such that prev_page and next_page are set to INVALID_PAGE_NUM, free_space_begin is set to sizeof(HeapPageHeader), free_space_end is set to PAGE_SIZE, size and capacity are set to 0.

◆ insertRecord()

SlotId HeapPage::insertRecord ( Data record_data)

Inserts given record data to the Page.

If there is enough free space on the Page, and valid record data is passed (the Data value has non-zero length), then the data are inserted into the page.

Precondition
: the slot directory has m used slots in its slot directory and all m records are compacted at the bottom of the page.
Postcondition
: after a successful insert, it has m+1 used slots in its solt directory (possibly increasing the slot directory size by one entry), and all m+1 records are compacted at the bottom of the page.
Parameters
record_data(a pointer to a Data of a record) to be inserted.
Returns
SlotId of the slot the Record is inserted to.
Exceptions
InsufficientSpaceHeapPageIf there is not enough space to insert the record on the page.
EmptyDataHeapPage.If the passed record data is size 0.

◆ isEmpty()

bool HeapPage::isEmpty ( )

bool function indicating whether the Page is empty.

Precondition
None.
Postcondition
true is returned if size is 0. Else false is returned.
Returns
bool indicating whether the Page is empty.

◆ isFull()

bool HeapPage::isFull ( )

bool function indicating whether the Page is full.

Precondition
None.
Postcondition
true is returned if used space/PAGE_SIZE exceeds MAX_HEAP_PAGE_LOAD and false is returned otherwise.
Returns
bool indicating whether the Page is full.

◆ setNext()

void HeapPage::setNext ( PageNum  page_num)

Sets next_page to the given PageNum.

Precondition
None.
Postcondition
next_page is set to the given PageNum.
Parameters
page_numPageNum of the next Page.

◆ setPrev()

void HeapPage::setPrev ( PageNum  page_num)

Set prev_page to the given PageNum.

Precondition
None.
Postcondition
prev_page is set to the given PageNum.
Parameters
page_numPageNum of the previous Page.

◆ updateRecord()

void HeapPage::updateRecord ( SlotId  slot_id,
Data record_data 
)

Updates Record identified by SlotId.

Precondition
A valid SlotId is provided as input and there is enough space in the Page for the updated Record. Valid Data * is provided as input.
Postcondition
The record stored in the slot identified by the given SlotId is updated to the passed record_data value. The record's slotId does not change as a result of a successful update. The orginal record data on the page should not be modified if there is not space on the page to update the record to its new value.
Parameters
slot_idSlotId of the Record to be updated.
record_dataData* of the updated Record.
Exceptions
InsufficientSpaceHeapPageIf there is not enough space for updated Record.
InvalidSlotIdHeapPageIf SlotId is invalid (SlotId is out of range or SlotInfo of the given SlotId has INVALID_SLOT_OFFSET).

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