-
Notifications
You must be signed in to change notification settings - Fork 0
/
BplusTree.h
132 lines (115 loc) · 3.67 KB
/
BplusTree.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#ifndef _BPLUSTREE_H_
#define _BPLUSTREE_H_
#include <stdio.h>
#include <stdlib.h>
#include <queue>
#include <string>
using namespace std;
#define ORDER 3
typedef struct word* Word; //Word is a pointer type other collaborators need
typedef struct Node* Nodeptr;
typedef enum { leaf, key } Nodetype; // Node type include "leaf" and "key"
typedef struct Hash{
long value;
Word pointer;
}Hash;
typedef struct Node{
Nodeptr child[ORDER + 1]; //the node's children's pointer in B+ tree
Nodeptr parent; //the node's parent's pointer in B+ tree
int num; //the number of child of key; or the number of element of leaf
long min; //the min ID of the node of this subtree whose root is this node
Hash content[ORDER + 1]; // store every node's values, if node is leaf, the Hash.pointer store sth we need
Nodetype type; // node's type, leaf or key(not leaf)
}Node;
/*
* it's a function to insert a node to the B+ tree
*---------------------------------------------------------------
* Input:
* root: the root of the tree(subtree) to be inserted
* digit: a part of the node(Hash)
* pointer: a part of the node(Hash)
*
* returns: root, the modified node
*/
Nodeptr insert(Nodeptr root, long digit, Word pointer);
/*
* it's a function to insert a digit and pointer to the sorted array(type Hash)
*---------------------------------------------------------------
* Input:
* num: the number of values in array
* a[]: the name(pointer) of array
* digit: the digit to be inserted
* pointer: the pointer to be inserted
*
* returns: i, the index of the inserting location
*/
int insert_arr(int num, Hash a[], long digit, Word pointer);
/*
* it's a function to check whether the node of B+ tree satisfies B+ tree's property
* if not, split the node and modify it to satisfies B+ tree's property
*---------------------------------------------------------------
* Input:
* root: the input node to be checked and modified
*
* returns: root, the modified node
*/
Nodeptr checkAndSplit(Nodeptr root);
/*
* it's a function to find a Node identified by a hash(digit)
*---------------------------------------------------------------
* Input:
* digit: a hash identifying the node of B+ tree
* root: the root of tree(subtree)
*
* returns: if find the node, then return the pointer(type Word) stored in this node
* if not find, return NULL
*/
Word Find(long digit, Nodeptr root);
/*
* it's a function to provide an interface to "wzj.cpp"
*---------------------------------------------------------------
* Input:
* digit: a part of the node(Hash) to be insertd
* pointer: a part of the node(Hash) to be insertd
*
* returns: void
*/
void inInsert(long digit, Word pointer);
/*
* it's a function to provide an interface to "wzj.cpp"
*---------------------------------------------------------------
* Input:
* digit: the ID of each node
*
* returns: void
*/
Word inFind(int digit);
/*
* it's a function to Initial the empty B+ tree
*---------------------------------------------------------------
* Input: void
*
* returns: void
*/
void treeInitial();
/*
* it's a function to traverse the entire B+ tree and
* return all pointers hanging at the bottom to the caller
*---------------------------------------------------------------
* Input: void
*
* returns: void
*/
void ergodicLeaf();
/*
* it's a function to traverse the entire B+ tree and
* return all pointers hanging at the bottom to the caller.
* Every time finding a leaf then call function "wordIntotxt",
* and give the pointer to it
*---------------------------------------------------------------
* Input: void
*
* returns: void
*/
void outToTxt(Nodeptr root);
#endif