SwatDB
Loading...
Searching...
No Matches
heapfile.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, 2025 Swarthmore College Computer Science Department
7 * Swarthmore PA, Professors Tia Newhall, Ameet Soni
8 */
9
10// @@@@ SWATDB_ASSIGNMENT: ADDTODODATE
11
12#ifndef _SWATDB_HEAPFILE_H_
13#define _SWATDB_HEAPFILE_H_
14
19#include <string>
20#include <vector>
21#include <mutex>
22#include "swatdb_types.h"
23#include "relationfile.h" //for inheritance
24
25class BufferManager;
26class HeapPage;
27class HeapPageScanner;
28class Schema;
29class Record;
30
34class HeapFile;
35
36// @@@@ SWATDB_ASSIGNMENT: NOTEMSG DO NOT modify this struct definition
42
47
52
56 std::uint32_t free_size;
57
61 std::uint32_t full_size;
62
66 std::uint64_t num_records;
67
68};
69
76class HeapFile : public RelationFile {
77 friend class Catalog;
78 friend class FileManager;
79 friend class HeapFileScanner;
80 friend class BlockHeapFileScanner;
81
82 public:
83
98
106
107
111 std::uint32_t getNumPages();
112
116 std::uint32_t getNumFullPages();
117
121 std::uint64_t getNumRecords();
122
136
149
177
178
199 void getRecord(RecordId record_id, Record* record);
200
229 void updateRecord(RecordId record_id, Record record);
230
252 void deleteRecord(RecordId record_id);
253
259
263 std::uint64_t getNumRecs();
264
265 // @@@@ SWATDB_ASSIGNMENT: CUT_START
285 // @@@@ SWATDB_ASSIGNMENT: CUT_END
286 // @@@@ SWATDB_ASSIGNMENT: NOTEMSG ignore this method: not part of heapile assn
288
289 // @@@@ SWATDB_ASSIGNMENT: CUT_START
300 // @@@@ SWATDB_ASSIGNMENT: CUT_END
301 // @@@@ SWATDB_ASSIGNMENT: NOTEMSG ignore this method: not part of heapile assn
303
304 private:
305
306 // @@@@ SWATDB_ASSIGNMENT: NOTEMSG add some private helper methods for good design
307 // @@@@ SWATDB_ASSIGNMENT: NOTEMSG you should not need to add any data fields
308 // @@@@ SWATDB_ASSIGNMENT: CUT_START
333 void _addPage(HeapPage* page, PageId page_id, bool full);
334
338 std::mutex *mtx;
339
364 void _removePage(HeapPage* page, PageId page_id, bool full);
365
367 // @@@@ SWATDB_ASSIGNMENT: CUT_END
368
369};
370
371#endif
Definition blockheapfilescanner.h:35
Definition bufmgr.h:121
Definition catalog.h:161
Definition filemgr.h:32
Catalog * catalog
Definition file.h:124
BufferManager * buf_mgr
Definition file.h:129
Definition heapfilescanner.h:39
Definition heapfile.h:76
std::uint32_t getNumFullPages()
Returns the number of full pages in the file.
void flushHeader()
Flushes header Page to disk.
PageId atomicAppend(PageId orig_pid)
Atomic append a page for heapfile. Acquires a mutex, adds page at the beginning of full list,...
void deleteRecord(RecordId record_id)
Deletes the Record identified by the given RecordId.
HeapFileHeader getHeader()
THIS METHOD IS FOR DEBUGGING ONLY. Returns the current HeapFileHeader.
void updateRecord(RecordId record_id, Record record)
Updates the record data in the HeapFile identified by the given RecordId to the data in the provided ...
RecordId insertRecord(Record record)
Inserts a Record into the HeapFile.
PageId anonAppend(PageId orig_pid)
Copies a page and inserts the copy into the begining of the full list. The contents are reset.
std::uint32_t getNumPages()
Returns the number of pages in the file.
std::uint64_t getNumRecords()
Returns the number of records in the file.
HeapFile(Catalog *catalog, BufferManager *buf_mgr, Schema *schema)
Constructor for HeapFile class.
void getRecord(RecordId record_id, Record *record)
Sets the record_data of the given Record pointer to the data corresponding to the given RecordId.
std::uint64_t getNumRecs()
This method returns the number of records in a file.
void createHeader()
Allocates and initializes the header Page of the file.
~HeapFile()
HeapFile destructor.
Definition heappagescanner.h:33
Definition heappage.h:94
Definition record.h:34
Definition relationfile.h:32
Schema * schema
Definition relationfile.h:105
Definition schema.h:37
Definition heapfile.h:41
std::uint64_t num_records
Definition heapfile.h:66
std::uint32_t free_size
Definition heapfile.h:56
std::uint32_t full_size
Definition heapfile.h:61
PageNum free
Definition heapfile.h:46
PageNum full
Definition heapfile.h:51
Definition swatdb_types.h:54
Definition swatdb_types.h:70
std::uint32_t PageNum
Definition swatdb_types.h:38