-
Notifications
You must be signed in to change notification settings - Fork 0
/
mybuffer.cpp
41 lines (34 loc) · 1.21 KB
/
mybuffer.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
#include <string>
#include <string.h>
#include "datatype.h"
//#include "BufferManager.h"
using namespace std;
blockInfo *get_new_block(const std::string& table_name, int fileType, int blockNum);
blockInfo *readBlock(const std::string& table_name, int fileType, int blockNum);
blockInfo *get_my_file_block(const std::string& database, const std::string& table_name, int fileType, int blockNum) {
blockInfo *node = readBlock(table_name, blockNum, fileType );
if (node == NULL) {
node = get_new_block(table_name, fileType, blockNum);
memset(node->cBlock, 0, 4096);
node->charNum = 0;
return node;
}
int i = -1;
while (node->cBlock[++i] != '\0');
node->charNum = i;
return node;
}
// blockNum == 0 --> search from beginning
// else search after the blockNum
blockInfo *get_my_new_block(const std::string& database, const std::string& table_name, int blockNum) {
blockInfo *node;
while (node = readBlock(table_name, ++blockNum, IndexFile)) {
if (node->cBlock[0] == '\0')
break;
}
if (node == NULL)
node = get_new_block(table_name, IndexFile, blockNum);
node->charNum = 0;
memset(node->cBlock, 0, 4096);
return node;
}