-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbp-tree.h
72 lines (52 loc) · 1.39 KB
/
bp-tree.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
#ifndef BPTREE_H
#define BPTREE_H
#include <iostream>
#include <vector>
using namespace std;
template<class K, class V>
class BpTree {
struct Node {
// Node básico padrão
bool leaf;
vector<K> key;
vector<V> value;
vector<Node*> children;
Node* parent;
Node* nextleaf;
Node(int);
};
public:
Node* root = nullptr;
int node_len = 5;
// Constructor
explicit BpTree(int node_len);
// Retorna o valor associado a chave key
V find(K x);
// retorna o valor dos nós no intervalo [k1, k2]
vector<V> findRange(K k1, K k2);
// Inserta uma nova chave
void insert(K x, V v);
// Remove uma chave
void remove(K x);
// Limpa a árvore
void clear();
// Imprime a árvore
void print();
private:
// Encontra o nó de insert
Node* searchNode(K x);
// Insere a chave no nó p
void insertIntoLeaf(Node* p, K x, V v);
// Insere a chave no nó pai p
void insertIntoParent(Node* p, Node* q, K x);
// Remove a chave no nó p
void removeKey(Node* p, K x);
// Limpa a árvore com função recursiva
void clear(Node* p);
// Retorna posição de divisão do nó no split
int getDivision();
// Retorna o valor mínimo de chaves que determina se um nó será reestruturado
int getThreshold(bool leaf);
};
#include "bp-tree.hpp"
#endif