-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRunMetadata.cpp
125 lines (97 loc) · 2.55 KB
/
RunMetadata.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
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
123
124
125
/*
* RunMetadata.cpp
*/
#include "RunMetadata.h"
#include <string>
#include <fcntl.h>
#include <unistd.h>
#include <cstring>
#include <iostream>
using namespace std;
/* Not technically required, but needed on some UNIX distributions */
#include <sys/types.h>
#include <sys/stat.h>
//------------------------ Constructors ---------------------
RunMetadata::RunMetadata(BloomFilter *bloomftr, FencePointer *fenceptrs, string filename, int size,
int numFencePtrs) {
this->bloomfilter = bloomftr;
this->fencepointers = fenceptrs;
this->filename = filename;
this->size = size;
this->numFencePointers = numFencePtrs;
}
RunMetadata::RunMetadata(BloomFilter *bloomftr, FencePointer *fenceptrs,
string filename, int size) : RunMetadata(bloomftr, fenceptrs, filename, size, 1) {
}
RunMetadata::RunMetadata(string filename) : RunMetadata(nullptr, nullptr, filename, 1) {
}
//------------------------ Getters ---------------------
string RunMetadata::getFilename() {
return this->filename;
}
BloomFilter *RunMetadata::getBloomFilter() {
return this->bloomfilter;
}
FencePointer *RunMetadata::getFencePointers() {
return this->fencepointers;
}
int RunMetadata::getNumFncPtrs() {
return this->numFencePointers;
}
int RunMetadata::getSize() {
return this->size;
}
//------------------------ Setters ---------------------
void RunMetadata::setFilename(string levelNumber) {
this->filename = levelNumber;
}
//------------------------ Range search ---------------------
/* binary search over fence pointers */
int RunMetadata::pageInRange(int query) {
int left = 0;
int right = numFencePointers - 1;
int mid, outcome;
while (left <= right) {
mid = (right + left) / 2;
outcome = fencepointers[mid].isInRange(query);
if (outcome == 0) {
return mid;
}
else if (outcome == 1) {
left = mid + 1;
}
else {
right = mid - 1;
}
}
/* didn' find it */
return -1;
}
int RunMetadata::pageRangeOverlaps(int low, int high) {
int left = 0;
int right = numFencePointers - 1;
int mid, outcome;
while (left <= right) {
mid = (right + left) / 2;
outcome = fencepointers[mid].rangeOverlaps(low, high);
if (outcome == 0) {
return mid;
}
else if (outcome == 1) {
left = mid + 1;
}
else {
right = mid - 1;
}
}
/* didn't find it */
return -1;
}
bool RunMetadata::mightContain(int query) {
return bloomfilter->contains(query);
}
//------------------------ Destructor ---------------------
RunMetadata::~RunMetadata() {
delete bloomfilter;
delete[] fencepointers;
}