forked from VastlyBlank/5300-Ocelot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBTreeNode.h
executable file
·91 lines (68 loc) · 2.68 KB
/
BTreeNode.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
#pragma once
#include "storage_engine.h"
#include "heap_storage.h"
typedef std::vector<ColumnAttribute::DataType> KeyProfile;
typedef std::vector<Value> KeyValue;
typedef std::vector<KeyValue*> KeyValues;
typedef std::vector<BlockID> BlockPointers;
typedef std::pair<BlockID,KeyValue> Insertion;
class BTreeNode {
public:
BTreeNode(HeapFile &file, BlockID block_id, const KeyProfile& key_profile, bool create);
virtual ~BTreeNode();
static bool insertion_is_none(Insertion insertion) { return insertion.first == 0; }
static Insertion insertion_none() { return Insertion(0, KeyValue()); }
virtual void save();
BlockID get_id() const { return this->id; }
protected:
SlottedPage *block;
HeapFile &file;
BlockID id;
const KeyProfile& key_profile;
static Dbt *marshal_block_id(BlockID block_id);
static Dbt *marshal_handle(Handle handle);
virtual Dbt *marshal_key(const KeyValue *key);
virtual BlockID get_block_id(RecordID record_id) const;
virtual Handle get_handle(RecordID record_id) const;
virtual KeyValue* get_key(RecordID record_id) const;
};
class BTreeStat : public BTreeNode {
public:
static const RecordID ROOT = 1; // where we store the root id in the stat block
static const RecordID HEIGHT = ROOT + 1; // where we store the height in the stat block
BTreeStat(HeapFile &file, BlockID stat_id, BlockID new_root, const KeyProfile& key_profile);
BTreeStat(HeapFile &file, BlockID stat_id, const KeyProfile& key_profile);
virtual ~BTreeStat() {}
virtual void save();
BlockID get_root_id() const { return this->root_id; }
void set_root_id(BlockID root_id) { this->root_id = root_id; }
uint get_height() const { return this->height; }
void set_height(uint height) { this->height = height; }
protected:
BlockID root_id;
uint height;
};
class BTreeInterior : public BTreeNode {
public:
BTreeInterior(HeapFile &file, BlockID block_id, const KeyProfile& key_profile, bool create);
virtual ~BTreeInterior();
BTreeNode *find(const KeyValue* key, uint depth) const;
Insertion insert(const KeyValue* boundary, BlockID block_id);
virtual void save();
void set_first(BlockID first) { this->first = first; }
protected:
BlockID first;
BlockPointers pointers;
KeyValues boundaries;
};
class BTreeLeaf : public BTreeNode {
public:
BTreeLeaf(HeapFile &file, BlockID block_id, const KeyProfile& key_profile, bool create);
virtual ~BTreeLeaf();
Handle find_eq(const KeyValue* key) const; // throws if not found
Insertion insert(const KeyValue* key, Handle handle);
virtual void save();
protected:
BlockID next_leaf;
std::map<KeyValue,Handle> key_map;
};