-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbt_builder.h
75 lines (58 loc) · 2.25 KB
/
bt_builder.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
// 91574 Database II - C++ Programming
// Swathi Kurunji, UMass Lowell, MA, 2011
// bt_builder.h - definition of class BtreeBuilder for this project.
#ifndef BT_BUILDER_H
#define BT_BUILDER_H
#include<iostream>
#include<cstdlib>
using namespace std;
#include "bt_errors.h"
#include "bt_node.h"
#include "bt_leaf.h"
#include "bt_index.h"
#include "bt_scan.h"
class BtreeBuilder
{
BtreeNode *root; //will point to root of the tree
public:
BtreeBuilder()
{
BtreeLeaf * btl = new BtreeLeaf();
root = btl;
};
virtual ~BtreeBuilder();
friend class BtreeScan;
//this function inserts key into B+ tree
//this traverses from root until leaf node is reached.
//inserts the key. If required splits node and propagates the split
//until a node which does not need split is reached
Status insertBuilderKey( KeyId );
//deletes the specified key from the tree
Status deleteBuilderKey( KeyId );
Status searchForLeafNode( KeyId, BtreeNode*, BtreeNode*&);
//1st argument(arg) is the key that we need to insert
//In 2nd arg, we store the key value that we need to insert in parent node after splitting node
//3rd is the node which is full and needs split
//4th and 5th holds the new left and right child address(we need to store this in parent node)
Status splitNode( KeyId, KeyId&, BtreeNode *, BtreeNode *&, BtreeNode *& );
// create a scan with given keys
// Cases:
// (1) lo_key = NULL, hi_key = NULL
// scan the whole index
// (2) lo_key = NULL, hi_key!= NULL
// range scan from min to the hi_key
// (3) lo_key!= NULL, hi_key = NULL
// range scan from the lo_key to max
// (4) lo_key!= NULL, hi_key!= NULL, lo_key = hi_key
// exact match ( might not unique)
// (5) lo_key!= NULL, hi_key!= NULL, lo_key < hi_key
// range scan from lo_key to hi_key
BtreeScan* openScan( KeyId lo_key = NULL, KeyId hi_key = NULL );
//find the starting position.
//scanTree function calls this function by passing lo_key to find the starting position in the B+tree.
//input are: pointer of scan object and lo_key
Status findStartPosition( BtreeScan *, KeyId );
//This function recursively deletes the whole B+tree
Status destroyBtree();
};
#endif