-
Notifications
You must be signed in to change notification settings - Fork 0
/
b_plus_tree.hpp
67 lines (56 loc) · 1.29 KB
/
b_plus_tree.hpp
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
//
// b_plus_tree.hpp
// COP5536 Adv. Data Struct.
// Created by Yinuo Yang
//
#include <deque>
#include <algorithm>
using namespace std;
class BpTree_Node;
class Pair{
public:
int key;
float value;
Pair();
};
class BpTree{
public:
BpTree_Node* root;
unsigned int m; // degree of the tree
BpTree();
Pair* search_key(int);
deque<Pair*>* search_range(int, int);
void insert(Pair*);
void del(int);
void grow();//increase 1 level of height
void shrink();//decrease 1 level of height
};
class BpTree_Node{
public:
unsigned int m; //same as degree of the tree
BpTree* tree;
BpTree_Node* parent;
deque<BpTree_Node*> children;
bool is_leaf;
BpTree_Node* prev;
BpTree_Node* next;
deque<unsigned int> keys;
deque<Pair*> data;
BpTree_Node();
BpTree_Node* search_leaf(int);
Pair* search_key(int);
BpTree_Node* split();
void insert(Pair*);
bool is_deficient();
void left_borrow();
void right_borrow();
void left_merge();
void right_merge();
void del_root();
void del(int);
void sort_keys();
void sort_children();
void sort_data();
};
bool compare_pairs(Pair*, Pair*);
bool compare_nodes(BpTree_Node*, BpTree_Node*);