-
Notifications
You must be signed in to change notification settings - Fork 0
/
BTKNode.h
100 lines (78 loc) · 2.27 KB
/
BTKNode.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
//
// Created by Sgofman on 08-Jan-18.
//
#ifndef FINALALGO_BTKNODE_H
#define FINALALGO_BTKNODE_H
#include <cstddef>
#include "Key.h"
#include "Value.h"
#include "ParameterK.h"
using namespace std;
class BTKNode {
friend class BalancedTreeK;
private:
BTKNode* parent; //Pointer to parent node
unsigned k; // Minimum degree (defines the range for number of keys)
BTKNode* Children[2*K-1]; // An array of child pointers, initially contain NULL
unsigned Cnum; // Current number of children
bool leaf; // Is true when node is leaf. Otherwise false
unsigned totaLeafs; // total number of leafs roted at this
Key* key; //key if leaf - maximum key in sub tree if not
Value* val; //value of leaf/ maximum val in sub tree
public:
BTKNode()
{
parent = NULL;
k = K;
for(int i =0; i < 2*k -1; i ++)
Children[i] = NULL;
Cnum = 0;
leaf = false;
totaLeafs = 0;
key = NULL;
val = NULL;
}
BTKNode(bool _leaf,Value* _val,Key* _key,BTKNode* newParent) //Normal Constructor
{
parent = newParent;
k = K;
for(int i =0; i < 2*k -1; i ++)
Children[i] = NULL;
Cnum = 0;
if (_leaf)
totaLeafs = 1;
else
totaLeafs = 0;
leaf = _leaf;
key=_key;
val=_val;
};
BTKNode& operator = (const BTKNode& other)
{
if(this != &other) // not the same entity
{
parent = other.parent;
k = other.k;
//Children = new BTKNode *[2*k -1];
for(int i =0; i < 2*k -1; i++)
Children[i] = other.Children[i];
Cnum = other.Cnum;
leaf = other.leaf;
totaLeafs = other.totaLeafs;
key = other.key->clone();
val = other.val->clone();
}
return *this;
};
~BTKNode();
BTKNode* SelectRec(unsigned index);
Value* Search(const Key* k);
BTKNode* SearchLeaf(const Key* k);
BTKNode* SearchRighty(const Key* k);
void UpdateKey();
void UpdateVal();
void SetChildren(BTKNode **children);
BTKNode* InsertAndSplit(BTKNode *z);
BTKNode* BorrowMerge();
};
#endif //FINALALGO_BTKNODE_H