SwatDB
Loading...
Searching...
No Matches
heappage.h
Go to the documentation of this file.
1/*
2 * SwatDB
3 *
4 * @authors: See Contributors.doc for code contributors
5 *
6 * Copyright (c) 2020 Swarthmore College Computer Science Department
7 * Swarthmore PA, Professors Tia Newhall, Ameet Soni
8 */
9
10// @@@@ SWATDB_ASSIGNMENT: ADDTODODATE
11
12#ifndef _SWATDB_HEAPPAGE_H_
13#define _SWATDB_HEAPPAGE_H_
14
15
20#include <cstddef>
21#include <mutex>
22#include "swatdb_types.h"
23#include "page.h"
24
25class Data;
26
30class HeapPage;
31
38
43
48
52 std::uint32_t free_space_begin;
53
57 std::uint32_t free_space_end;
58
62 std::uint32_t size;
63
67 std::uint32_t capacity;
68};
69
75struct SlotInfo{
76
81 uint32_t offset;
82
86 uint32_t length;
87};
88
94class HeapPage : public Page {
95
96 friend class HeapPageScanner;
97
98 public:
99
108 HeapPage() = delete;
109
114
125
134 void setNext(PageNum page_num);
135
144 void setPrev(PageNum page_num);
145
155
165
166
182 std::uint32_t getFreeSpace();
183
184 // @@@@ SWATDB_ASSIGNMENT: CUT_START
189 // @@@@ SWATDB_ASSIGNMENT: CUT_END
190
200 // @@@@ SWATDB_ASSIGNMENT: CUT_START
201 // @post true is returned if used space/PAGE_SIZE exceeds
202 // MAX_HEAP_PAGE_LOAD and false is returned otherwise.
203 // @@@@ SWATDB_ASSIGNMENT: CUT_END
204 bool isFull();
205
214 bool isEmpty();
215
238 SlotId insertRecord(Data *record_data);
239
256 void getRecord(SlotId slot_id, Data *data);
257
276 void deleteRecord(SlotId slot_id);
277
298 void updateRecord(SlotId slot_id, Data *record_data);
299
305
312 SlotInfo getSlotInfo(SlotId slot_id);
313
319 std::uint32_t getInvalidNum();
320
326
327 // @@@@ SWATDB_ASSIGNMENT: CUT_START
332 void removeAll();
333 // @@@@ SWATDB_ASSIGNMENT: CUT_END
334
338 std::uint32_t getNumRecs();
339
340 private:
341
348
359
360 // @@@@ SWATDB_ASSIGNMENT: CUT_START
380 SlotId _getFreeSlot();
382 // @@@@ SWATDB_ASSIGNMENT: CUT_END
383
398 SlotInfo* _getSlotInfo(SlotId slot_id);
401 // @@@@ SWATDB_ASSIGNMENT: CUT_START
403 // @@@@ SWATDB_ASSIGNMENT: CUT_END
427 void _insertRecord(SlotId slot_id, Data* record_data);
428 // @@@@ SWATDB_ASSIGNMENT: CUT_START
430 // @@@@ SWATDB_ASSIGNMENT: CUT_END
431
432 // @@@@ SWATDB_ASSIGNMENT: CUT_START
434 // @@@@ SWATDB_ASSIGNMENT: CUT_END
451 // @@@@ SWATDB_ASSIGNMENT: CUT_START
452 //If free_space_end is less than the slot offset of the corresponding
453 // slot info, the records to the left of the record to be deleted are
454 // shifted to right by the size of the deleted record, effectively
455 // compactifying space occupied by the records. The slot offset of all
456 // shifted records are updated accordingly. free_space_end is
457 // incremented by the size of the deleted record. Page header size is
458 // decremented.
459 // @@@@ SWATDB_ASSIGNMENT: CUT_END
460 void _deleteRecord(SlotId slot_id);
461 // @@@@ SWATDB_ASSIGNMENT: CUT_START
463 // @@@@ SWATDB_ASSIGNMENT: CUT_END
464
465};
466
467#endif
Definition data.h:26
Definition heappagescanner.h:33
Definition heappage.h:94
void removeAll()
Removes all the records from the page.
std::uint32_t getInvalidNum()
THIS METHOD IS FOR DEBUGGING ONLY.
SlotInfo getSlotInfo(SlotId slot_id)
THIS METHOD IS FOR DEBUGGING ONLY.
SlotId insertRecord(Data *record_data)
Inserts given record data to the Page.
std::uint32_t getNumRecs()
Returns the amount of records in the page.
HeapPageHeader * _getPageHeader()
Getter for the Page header.
void deleteRecord(SlotId slot_id)
Deletes record identified by SlotId.
void updateRecord(SlotId slot_id, Data *record_data)
Updates record identified by SlotId.
~HeapPage()
Definition heappage.h:113
void setPrev(PageNum page_num)
Set prev_page to the given PageNum.
PageNum getPrev()
Getter for prev_page.
bool isEmpty()
bool function indicating whether the Page is empty.
bool isFull()
bool function indicating whether the Page is full.
void getRecord(SlotId slot_id, Data *data)
Gets the record identified by its SlotId.
void setNext(PageNum page_num)
Sets next_page to the given PageNum.
HeapPageHeader getHeader()
THIS METHOD IS FOR DEBUGGING ONLY. Returns this HeapPage's header information.
HeapPage()=delete
Constructor.
SlotInfo * _getSlotDirectory()
Return pointer to the where slot directory begins (first SlotInfo)
PageNum getNext()
Getter for next_page.
void zeroFreeSpace()
zeroes out the free space on a heap page.
void initializeHeader()
Initializes header information after the Page is allocated.
std::uint32_t getFreeSpace()
Getter for the amount of free space on the Page that is available to insert a new record.
void printHeapPageState()
THIS METHOD IS FOR DEBUGGING ONLY. Prints the current state of the HeapPage.
Definition page.h:27
char data[PAGE_SIZE]
char array that stores the page data. Derived classes could map appropriate structures on it.
Definition page.h:60
Definition heappage.h:37
std::uint32_t free_space_end
Definition heappage.h:57
std::uint32_t size
Definition heappage.h:62
PageNum next_page
Definition heappage.h:47
PageNum prev_page
Definition heappage.h:42
std::uint32_t free_space_begin
Definition heappage.h:52
std::uint32_t capacity
Definition heappage.h:67
Definition hashbucketpage.h:76
uint32_t offset
Definition heappage.h:81
uint32_t length
Definition heappage.h:86
std::uint32_t PageNum
Definition swatdb_types.h:38