#include <heappage.h>
|
char | data [PAGE_SIZE] |
| char array that stores the page data. Derived classes could map appropriate structures on it.
|
|
SwatDB HeapPage Class. HeapPage inherits from base Page class and instantiates heap page, collection of which, form HeapFile.
◆ HeapPage()
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()
◆ _getPageHeader()
◆ _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_id | SlotId 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_id | SlotId of the Record to be deleted. |
- Exceptions
-
◆ 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()
Getter for next_page.
- Precondition
- None.
- Postcondition
- next_page of the page header is returned.
- Returns
- PageNum of the next Page.
◆ 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_id | SlotId of the Record to be retrieved |
- Exceptions
-
◆ 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
-
InsufficientSpaceHeapPage | If 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_num | PageNum 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_num | PageNum 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_id | SlotId of the Record to be updated. |
record_data | Data* of the updated Record. |
- Exceptions
-
The documentation for this class was generated from the following file: