-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiskPage.cpp
executable file
·70 lines (63 loc) · 1.95 KB
/
DiskPage.cpp
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
#include <stdio.h>
#include <iostream>
#include "DiskPage.h"
#include "Attribute.h"
DiskPage::DiskPage(const PageLayout * layout, MemoryBlock * block,
const std::string & table)
{
m_block = block;
m_table = table;
m_layout = layout;
}
size_t DiskPage::size() const
{
return m_block->getSize();
}
size_t DiskPage::capacity() const
{
return m_block->capacity();
}
void DiskPage::get(int rid, const Schema * fields,
byte * buffer, size_t length)
{
int numFields = fields->nitems();
int totalNumBytes = fields->rsize();
int currentLoc = 0;
for (int j=0; j < numFields; j++)
{
int fieldNum = fields->at(j)->id();
int fieldSize = m_layout->getFieldsBytes(fieldNum);
int locByte = m_layout->getFieldLoc(fieldNum);
int partition = m_layout->getFieldsPartition(fieldNum);
int partitionStart = m_layout->getPartitionStart(partition);
int partitionBytes = m_layout->getPartitionBytes(partition);
int offset = partitionStart + partitionBytes*rid + locByte;
byte * bLoc = & buffer[currentLoc];
m_block->get(bLoc, offset, fieldSize);
currentLoc += fieldSize;
}
}
void DiskPage::get(int rid, const std::vector<const Attribute *> & fields, byte * buffer, size_t length)
{
int numFields = fields.size();
int totalNumBytes = 0;
for (int i = 0; i < numFields; i++)
{
int numBytes = fields.at(i)->size();
totalNumBytes += numBytes;
}
int currentLoc = 0;
for (int j=0; j < numFields; j++)
{
int fieldNum = fields.at(j)->id();
int fieldSize = m_layout->getFieldsBytes(fieldNum);
int locByte = m_layout->getFieldLoc(fieldNum);
int partition = m_layout->getFieldsPartition(fieldNum);
int partitionStart = m_layout->getPartitionStart(partition);
int partitionBytes = m_layout->getPartitionBytes(partition);
int offset = partitionStart + partitionBytes*rid + locByte;
byte * bLoc = & buffer[currentLoc];
m_block->get(bLoc, offset, fieldSize);
currentLoc += fieldSize;
}
}