-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIX_Manager.cpp
More file actions
87 lines (68 loc) · 2.05 KB
/
IX_Manager.cpp
File metadata and controls
87 lines (68 loc) · 2.05 KB
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
#include "stdafx.h"
#include "IX_Manager.h"
int threshold;
RC CreateIndex(const char * fileName, AttrType attrType, int attrLength) {
CreateFile(fileName);
PF_FileHandle fileHandle;
openFile((char *)(void *)fileName, &fileHandle);
PF_PageHandle firstPageHandle;
AllocatePage(&fileHandle, &firstPageHandle);
PageNum pageNum;
GetPageNum(&firstPageHandle, &pageNum);
char *pData;
GetData(&firstPageHandle, &pData);
IX_FileHeader *header = (IX_FileHeader *)pData;
IX_Node* root = (IX_Node*)(pData + sizeof(IX_FileHeader));
header->attrLength = attrLength;
header->keyLength = attrLength + sizeof(RID);
header->attrType = attrType;
header->rootPage = pageNum;
header->first_leaf = pageNum;
int order = (PF_PAGE_SIZE - (sizeof(IX_FileHeader) + sizeof(IX_Node))) / (2 * sizeof(RID) + attrLength);
header->order = order;
root->brother = 0;
root->is_leaf = 1;
root->keynum = 0;
root->parent = 0;
MarkDirty(&firstPageHandle);
UnpinPage(&firstPageHandle);
CloseFile(&fileHandle);
return SUCCESS;
}
RC OpenIndex(const char *fileName, IX_IndexHandle *indexHandle) {
RC rc;
if ((rc = openFile((char *)(void *)fileName, &indexHandle->fileHandle)) != SUCCESS) {
return rc;
}
PF_PageHandle pageHandle;
GetThisPage(&indexHandle->fileHandle, 1, &pageHandle);
char *pData;
GetData(&pageHandle, &pData);
memcpy(&indexHandle->fileHeader, pData, sizeof(IX_FileHeader)); //复制第一页索引控制信息
indexHandle->bOpen = true;
return SUCCESS;
}
RC CloseIndex(IX_IndexHandle *indexHandle) {
CloseFile(&indexHandle->fileHandle);
return SUCCESS;
}
RC InsertEntry(IX_IndexHandle * indexHandle, void * pData, const RID * rid)
{
return SUCCESS;
}
RC DeleteEntry(IX_IndexHandle * indexHandle, void * pData, const RID * rid)
{
return SUCCESS;
}
RC OpenIndexScan(IX_IndexScan *indexScan, IX_IndexHandle *indexHandle, CompOp compOp, char *value) {
return SUCCESS;
}
RC IX_GetNextEntry(IX_IndexScan *indexScan, RID * rid) {
return SUCCESS;
}
RC CloseIndexScan(IX_IndexScan *indexScan) {
return SUCCESS;
}
RC GetIndexTree(char *fileName, Tree *index) {
return SUCCESS;
}