-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyPAGE.cc
66 lines (49 loc) · 1.07 KB
/
myPAGE.cc
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
#include "myPAGE.hh"
Page::Page()
{
page_size = 512;
MAX_TUPLES = page_size / sizeof(struct tuple);
curr_size = 0;
}
/* insert tuple into page */
void Page::insertTuple(struct tuple tup)
{
// insert into tuple into page
tuples.push_back(tup);
ids.push_back(tup.ID);
curr_size += sizeof(tup);
}
struct tuple Page::scan(int id){
// iterate over vector, get iterator if exists
vector<int>::iterator it = find(ids.begin(), ids.end(), id);
if (it != ids.end()) { // if exists
// return value at that index
int cur_index = (int)( it - ids.begin() );
return tuples[ cur_index ];
} else { // else return null
struct tuple empty;
empty.ID = -1;
return empty;
}
}
/* check if page is full */
bool Page::isFull(int size){
if( (curr_size+size) > page_size)
return true;
else
return false;
}
bool Page::isEmpty(){
if(tuples.empty())
return true;
else
return false;
}
/* return the array of tupples */
struct tuple* Page::getBuffer(){
return &tuples[0];
}
/* empties the buffer of records */
void Page::dumpPage(){
tuples.clear();
}