-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathix_hash.h
108 lines (78 loc) · 2.71 KB
/
ix_hash.h
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
#ifndef IX_HASH_H
#define IX_HASH_H
#include "pf.h"
#include "rm_rid.h"
#include "ix_common.h"
class IX_Hash
{
friend class IX_IndexHandle;
friend class IX_Manager;
friend class IX_IndexScan;
friend class IX_HashScan;
public:
IX_Hash();
~IX_Hash();
struct IX_DirectoryHdr {
int depth;
int nbFilledSlots;
PageNum next;
};
template <typename T, int n>
struct IX_Bucket {
int depth;
int nbFilledSlots;
T v[n];
PageNum child[n];
};
struct IX_RidBucketHdr {
int nbFilledSlots;
};
void setFileHandle(PF_FileHandle & iPfFileHandle) { _pPfFileHandle = &iPfFileHandle; }
void setFileHdr(IX_FileHdr & iFileHdr) { _pFileHdr = &iFileHdr; }
// Insert a new index entry
RC InsertEntry(void *pData, const RID &rid);
// Delete a new index entry
RC DeleteEntry(void *pData, const RID &rid);
// Display
RC DisplayTree();
private:
// insertion
template <typename T, int n>
RC InsertEntry_t(T iValue, const RID &rid);
template <typename T, int n>
RC InsertEntryInBucket_t(PageNum iPageNum, T iValue, const RID &rid);
RC InsertEntryInRidBucket(PageNum iPageNum, const RID &rid);
template <typename T, int n>
RC DivideBucketInTwo_t(const PageNum iBucketNum, PageNum &oBucketNum);
template <typename T, int n>
RC IsPossibleToInsertInBucket_t(const PageNum iPageNum, bool &needToDivide, int &childDepth);
// deletion
template <typename T, int n>
RC DeleteEntry_t(T iValue, const RID &rid);
template <typename T, int n>
RC DeleteEntryInBucket_t(PageNum iPageNum, T iValue, const RID &rid);
RC DeleteEntryInRidBucket(PageNum &ioPageNum, const RID &rid);
// print
template <typename T, int n>
RC DisplayTree_t();
template <typename T, int n>
RC DisplayBucket_t(const PageNum iPageNum);
template <typename T, int n>
RC AllocateDirectoryPage_t(PageNum &oPageNum);
template <typename T, int n>
RC AllocateBucketPage_t(const int depth, PageNum &oPageNum);
RC AllocateRidBucketPage(PageNum &oPageNum);
// page management
RC GetPageBuffer(const PageNum &iPageNum, char * &pBuffer) const;
RC ReleaseBuffer(const PageNum &iPageNum, bool isDirty) const;
template <typename T, int n>
RC GetBucketBuffer(const PageNum &iPageNum, IX_Bucket<T,n> * & pBuffer) const;
// directory management
RC GetBucketNum(const int binary, PageNum &oBucketNum);
template <typename T,int n>
RC DoubleDirectorySize_t();
RC UpdateDirectoryEntries(const int iBinary, const int iOffset, const PageNum &newPage, bool updateThisSlot);
PF_FileHandle *_pPfFileHandle;
IX_FileHdr * _pFileHdr;
};
#endif // IX_HASH_H