forked from Uradouby/cs660-pa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBTreeRootPtrPage.h
More file actions
100 lines (88 loc) · 3.28 KB
/
Copy pathBTreeRootPtrPage.h
File metadata and controls
100 lines (88 loc) · 3.28 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
#ifndef DB_BTREE_ROOTPTRPAGE_H
#define DB_BTREE_ROOTPTRPAGE_H
#include <db/Page.h>
#include <db/BTreePageId.h>
namespace db {
/**
* BTreeRootPtrPage stores the pointer to the root node used in the B+ tree and
* implements Page Interface that is used by BufferPool
*
* @see BufferPool
*/
class BTreeRootPtrPage : public Page {
// size of this page
const static int PAGE_SIZE = 9;
const BTreePageId *pid;
int root;
int header;
BTreePageType rootCategory;
public:
/**
* Constructor.
* Construct the BTreeRootPtrPage from a set of bytes of data read from
* disk.
* The format of an BTreeRootPtrPage is an integer for the page number
* of the root node, followed by a byte to encode the category of the root page
* (either leaf or internal), followed by an integer for the page number
* of the first header page
*/
BTreeRootPtrPage(const BTreePageId *id, void *data);
/**
* @return the PageId associated with this page.
*/
const PageId &getId() const override;
/**
* There is only one instance of a BTreeRootPtrPage per table. This static
* method is separate from getId() in order to maintain the Page interface
* @param tableid - the tableid of this table
* @return the root pointer page id for the given table
*/
static BTreePageId *getId(int tableid);
/**
* Generates a byte array representing the contents of this root pointer page.
* Used to serialize this root pointer page to disk.
* The invariant here is that it should be possible to pass the byte array
* generated by getPageData to the BTreeRootPtrPage constructor and have it
* produce an identical BTreeRootPtrPage object.
*
* @return A byte array corresponding to the bytes of this root pointer page.
*/
void *getPageData() const override;
/**
* Static method to generate a byte array corresponding to an empty
* BTreeRootPtrPage.
* Used to add new, empty pages to the file. Passing the results of
* this method to the BTreeRootPtrPage constructor will create a BTreeRootPtrPage with
* no valid entries in it.
*
* @return The returned ByteArray.
*/
static void *createEmptyPageData();
/**
* Get the id of the root page in this B+ tree
* @return the id of the root page
*/
BTreePageId *getRootId();
/**
* Set the id of the root page in this B+ tree
* @param id - the id of the root page
*/
void setRootId(const BTreePageId *id);
/**
* Get the id of the first header page, or null if none exists
* @return the id of the first header page
*/
BTreePageId *getHeaderId() const;
/**
* Set the page id of the first header page
* @param id - the id of the first header page
*/
void setHeaderId(const BTreePageId *id);
/**
* Get the page size of root pointer pages
* @return the page size
*/
static int getPageSize();
};
}
#endif