-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatabaseNode.h
64 lines (48 loc) · 1.39 KB
/
DatabaseNode.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
#pragma once
#include <vector>
#include "Page.h"
#include "PageReadWriter.h"
#include "GlobalConfiguration.h"
class DatabaseNode
{
public:
struct Record
{
Record(size_t size = 0, char *data = nullptr);
bool operator<(const Record &a) const;
bool operator>(const Record &a) const;
bool operator==(const Record &a) const;
static Record rawCopyFrom(const Record &a);
size_t size;
char *data;
};
DatabaseNode(
GlobalConfiguration *globConf,
PageReadWriter &rw,
size_t rootPageNumber,
bool needRead);
~DatabaseNode();
void writeToPages(GlobalConfiguration *globConf, PageReadWriter &rw);
bool isLeaf() const;
void setIsLeaf(bool val);
size_t keyCount() const;
void setKeyCount(size_t newsize);
std::vector<Record> &keys();
std::vector<Record> &data();
std::vector<size_t> &linkedNodesRootPageNumbers();
size_t rootPage() const;
void freePages(PageReadWriter &rw);
size_t spaceOnDisk() const;
size_t additionalSpaceFor(const Record &key, const Record &data) const;
size_t findFirstExceeding(size_t limitSize) const;
private:
bool m_isLeaf;
size_t m_keyCount;
size_t m_rootPageNumber;
std::vector<Record> m_keys;
std::vector<Record> m_data;
std::vector<size_t> m_linkedNodesRootPageNumbers;
DatabaseNode();
DatabaseNode(const DatabaseNode &) { }
void operator=(const DatabaseNode &p) { }
};