-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathb_plus_tree_page.h
68 lines (56 loc) · 2.08 KB
/
b_plus_tree_page.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
//===----------------------------------------------------------------------===//
//
// CMU-DB Project (15-445/645)
// ***DO NO SHARE PUBLICLY***
//
// Identification: src/include/page/b_plus_tree_page.h
//
// Copyright (c) 2018, Carnegie Mellon University Database Group
//
//===----------------------------------------------------------------------===//
#pragma once
#include <cassert>
#include <climits>
#include <cstdlib>
#include <string>
#include <utility>
#include "buffer/buffer_pool_manager.h"
#include "storage/index/generic_key.h"
namespace bustub {
template <typename KeyType, typename ValueType>
using MappingType_ = std::pair<KeyType, ValueType>;
#define INDEX_TEMPLATE_ARGUMENTS template <typename KeyType, typename ValueType, typename KeyComparator>
// define page type enum
enum class IndexPageType { INVALID_INDEX_PAGE = 0, LEAF_PAGE, INTERNAL_PAGE };
/**
* Both internal and leaf page are inherited from this page.
*
* It actually serves as a header part for each B+ tree page and
* contains information shared by both leaf page and internal page.
*
* Header format (size in byte, 12 bytes in total):
* ----------------------------------------------------------------------------
* | PageType (4) | CurrentSize (4) | MaxSize (4) |
* ----------------------------------------------------------------------------
*/
class BPlusTreePage {
public:
// Delete all constructor / destructor to ensure memory safety
BPlusTreePage() = delete;
BPlusTreePage(const BPlusTreePage &other) = delete;
~BPlusTreePage() = delete;
auto IsLeafPage() const -> bool;
void SetPageType(IndexPageType page_type);
auto GetSize() const -> int;
void SetSize(int size);
void IncreaseSize(int amount);
auto GetMaxSize() const -> int;
void SetMaxSize(int max_size);
auto GetMinSize() const -> int;
private:
// member variable, attributes that both internal and leaf page share
IndexPageType page_type_ __attribute__((__unused__));
int size_ __attribute__((__unused__));
int max_size_ __attribute__((__unused__));
};
} // namespace bustub