forked from Uradouby/cs660-pa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBTreeHeaderPage.h
More file actions
122 lines (104 loc) · 3.6 KB
/
Copy pathBTreeHeaderPage.h
File metadata and controls
122 lines (104 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#ifndef DB_BTREE_HEADERPAGE_H
#define DB_BTREE_HEADERPAGE_H
#include <db/Page.h>
#include <db/BTreePageId.h>
#include <cstdint>
namespace db {
/**
* Each instance of BTreeHeaderPage stores data for one page of a BTreeFile and
* implements the Page interface that is used by BufferPool.
*
* @see BTreeFile
* @see BufferPool
*
*/
class BTreeHeaderPage : public Page {
int nextPage; // next header page or 0
int prevPage; // previous header page or 0
const BTreePageId *pid;
uint8_t *header;
int numSlots;
/**
* Computes the number of bytes in the header while saving room for pointers
*/
static int getHeaderSize();
public:
/**
* Create a BTreeHeaderPage from a set of bytes of data read from disk.
* The format of a BTreeHeaderPage is two pointers to the next and previous
* header pages, followed by a set of bytes indicating which pages in the file
* are used or available
* @see BufferPool#getPageSize()
*
*/
BTreeHeaderPage(const BTreePageId *id, uint8_t *data);
/**
* Initially mark all slots in the header used.
*/
void init();
/**
* Computes the number of slots in the header
*/
static int getNumSlots();
/**
* @return the PageId associated with this page.
*/
const BTreePageId &getId() const override;
/**
* Generates a byte array representing the contents of this page.
* Used to serialize this page to disk.
* <p>
* The invariant here is that it should be possible to pass the byte
* array generated by getPageData to the BTreeHeaderPage constructor and
* have it produce an identical BTreeHeaderPage object.
*
* @see #BTreeHeaderPage
* @return A byte array correspond to the bytes of this page.
*/
void *getPageData() const override;
/**
* Static method to generate a byte array corresponding to an empty
* BTreeHeaderPage.
* Used to add new, empty pages to the file. Passing the results of
* this method to the BTreeHeaderPage constructor will create a BTreeHeaderPage with
* no valid data in it.
*
* @return The returned ByteArray.
*/
static void *createEmptyPageData();
/**
* Get the page id of the previous header page
* @return the page id of the previous header page
*/
BTreePageId *getPrevPageId();
/**
* Get the page id of the next header page
* @return the page id of the next header page
*/
BTreePageId *getNextPageId();
/**
* Set the page id of the previous header page
* @param id - the page id of the previous header page
*/
void setPrevPageId(const BTreePageId *id);
/**
* Set the page id of the next header page
* @param id - the page id of the next header page
*/
void setNextPageId(const BTreePageId *id);
/**
* Returns true if the page of the BTreeFile associated with slot i is used
*/
bool isSlotUsed(int i);
/**
* Abstraction to mark a page of the BTreeFile used or unused
*/
void markSlotUsed(int i, bool value);
/**
* get the index of the first empty slot
* @return the index of the first empty slot or -1 if none exists
*/
int getEmptySlot();
};
}
#endif