SwatDB
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 #pragma once
11 
16 #include <cstddef>
17 #include <mutex>
18 #include "swatdb_types.h"
19 #include "page.h"
20 
21 class Data;
22 
26 class HeapPage;
27 
34 
39 
44 
48  std::uint32_t free_space_begin;
49 
53  std::uint32_t free_space_end;
54 
58  std::uint32_t size;
59 
63  std::uint32_t capacity;
64 };
65 
70 struct SlotInfo{
71 
76  uint32_t offset;
77 
81  uint32_t length;
82 };
83 
89 class HeapPage : public Page {
90 
91  friend class HeapPageScanner;
92 
93  public:
94 
103  HeapPage() = delete;
104 
109 
119  void initializeHeader();
120 
129  void setNext(PageNum page_num);
130 
139  void setPrev(PageNum page_num);
140 
149  PageNum getNext();
150 
159  PageNum getPrev();
160 
161 
173  std::uint32_t getFreeSpace();
174 
184  bool isFull();
185 
194  bool isEmpty();
195 
218  SlotId insertRecord(Data *record_data);
219 
236  void getRecord(SlotId slot_id, Data *data);
237 
256  void deleteRecord(SlotId slot_id);
257 
278  void updateRecord(SlotId slot_id, Data *record_data);
279 
284  HeapPageHeader getHeader();
285 
290  SlotInfo getSlotInfo(SlotId slot_id);
291 
296  std::uint32_t getInvalidNum();
297 
302  void printHeapPageState();
303 
304  private:
305 
311  HeapPageHeader* _getPageHeader();
312 
322  SlotInfo* _getSlotDirectory();
323 
343  SlotId _getFreeSlot();
360  SlotInfo* _getSlotInfo(SlotId slot_id);
379  void _insertRecord(SlotId slot_id, Data* record_data);
401  void _deleteRecord(SlotId slot_id);
404 };
SlotId getNext()
Returns SlotId of the next valid slot.
uint32_t offset
Definition: heappage.h:76
std::uint32_t free_space_end
Definition: heappage.h:53
std::uint32_t PageNum
Definition: swatdb_types.h:34
PageNum prev_page
Definition: heappage.h:38
Definition: heappage.h:33
uint32_t length
Definition: heappage.h:81
std::uint32_t capacity
Definition: heappage.h:63
std::uint32_t size
Definition: heappage.h:58
~HeapPage()
Definition: heappage.h:108
Definition: heappage.h:89
PageNum next_page
Definition: heappage.h:43
Definition: heappage.h:70
std::uint32_t free_space_begin
Definition: heappage.h:48
Definition: data.h:25
Definition: heappagescanner.h:31
Definition: page.h:25