-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage.h
74 lines (58 loc) · 2.33 KB
/
page.h
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
#ifndef PAGE_H
#define PAGE_H
#include "error.h"
struct RID{
int pageNo;
int slotNo;
};
const RID NULLRID = {-1,-1};
struct Record
{
void* data;
int length;
};
// slot structure
struct slot_t {
short offset;
short length; // equals -1 if slot is not in use
};
const unsigned PAGESIZE = 1024;
const unsigned DPFIXED= sizeof(slot_t)+4*sizeof(short)+2*sizeof(int);
const unsigned PAGEDATASIZE = PAGESIZE-DPFIXED+sizeof(slot_t);
// size of the data area of a page
// Class definition for a minirel data page.
// The design assumes that records are kept compacted when
// deletions are performed. Notice, however, that the slot
// array cannot be compacted. Notice, this class does not keep
// the records align, relying instead on upper levels to take
// care of non-aligned attributes
class Page {
private:
char data[PAGESIZE - DPFIXED];
slot_t slot[1]; // first element of slot array - grows backwards!
short slotCnt; // number of slots in use;
short freePtr; // offset of first free byte in data[]
short freeSpace; // number of bytes free in data[]
short dummy; // for alignment purposes
int nextPage; // forwards pointer
int curPage; // page number of current pointer
public:
void init(const int pageNo); // initialize a new page
void dumpPage() const; // dump contents of a page
const Status getNextPage(int& pageNo) const; // returns value of nextPage
const Status setNextPage(const int pageNo); // sets value of nextPage to pageNo
const short getFreeSpace() const; // returns amount of free space
// inserts a new record (rec) into the page, returns RID of record
const Status insertRecord(const Record & rec, RID& rid);
// delete the record with the specified rid
const Status deleteRecord(const RID & rid);
// returns RID of first record on page
// returns NORECORDS if page contains no records. Otherwise, returns OK
const Status firstRecord(RID& firstRid) const;
// returns RID of next record on the page
// returns ENDOFPAGE if no more records exist on the page
const Status nextRecord (const RID & curRid, RID& nextRid) const;
// returns reference to record with RID rid
const Status getRecord(const RID & rid, Record & rec);
};
#endif