@@ -20,29 +20,30 @@ namespace bustub {
20
20
#define B_PLUS_TREE_INTERNAL_PAGE_TYPE BPlusTreeInternalPage<KeyType, ValueType, KeyComparator>
21
21
#define INTERNAL_PAGE_HEADER_SIZE 12
22
22
#define INTERNAL_PAGE_SIZE ((BUSTUB_PAGE_SIZE - INTERNAL_PAGE_HEADER_SIZE) / (sizeof (MappingType)))
23
+
23
24
/* *
24
- * Store n indexed keys and n+1 child pointers (page_id) within internal page.
25
+ * Store `n` indexed keys and `n + 1` child pointers (page_id) within internal page.
25
26
* Pointer PAGE_ID(i) points to a subtree in which all keys K satisfy:
26
27
* K(i) <= K < K(i+1).
27
- * NOTE: since the number of keys does not equal to number of child pointers,
28
- * the first key always remains invalid. That is to say, any search/ lookup
28
+ * NOTE: Since the number of keys does not equal to number of child pointers,
29
+ * the first key always remains invalid. That is to say, any search / lookup
29
30
* should ignore the first key.
30
31
*
31
32
* Internal page format (keys are stored in increasing order):
32
- * --------------------------------------------------------------------------
33
- * | HEADER | KEY(1)+ PAGE_ID(1) | KEY(2)+ PAGE_ID(2) | ... | KEY(n)+ PAGE_ID(n) |
34
- * --------------------------------------------------------------------------
33
+ * -------- --------------------------------------------------------------------------
34
+ * | HEADER | KEY(1) + PAGE_ID(1) | KEY(2) + PAGE_ID(2) | ... | KEY(n) + PAGE_ID(n) |
35
+ * -------- --------------------------------------------------------------------------
35
36
*/
36
37
INDEX_TEMPLATE_ARGUMENTS
37
38
class BPlusTreeInternalPage : public BPlusTreePage {
38
39
public:
39
- // Deleted to disallow initialization
40
+ // Delete all constructor / destructor to ensure memory safety
40
41
BPlusTreeInternalPage () = delete ;
41
42
BPlusTreeInternalPage (const BPlusTreeInternalPage &other) = delete ;
42
43
43
44
/* *
44
45
* Writes the necessary header information to a newly created page, must be called after
45
- * the creation of a new page to make a valid BPlusTreeInternalPage
46
+ * the creation of a new page to make a valid ` BPlusTreeInternalPage`
46
47
* @param max_size Maximal size of the page
47
48
*/
48
49
void Init (int max_size = INTERNAL_PAGE_SIZE);
@@ -54,36 +55,34 @@ class BPlusTreeInternalPage : public BPlusTreePage {
54
55
auto KeyAt (int index) const -> KeyType;
55
56
56
57
/* *
57
- *
58
58
* @param index The index of the key to set. Index must be non-zero.
59
59
* @param key The new value for key
60
60
*/
61
61
void SetKeyAt (int index, const KeyType &key);
62
62
63
63
/* *
64
- *
65
- * @param value the value to search for
64
+ * @param value The value to search for
65
+ * @return The index that corresponds to the specified value
66
66
*/
67
67
auto ValueIndex (const ValueType &value) const -> int;
68
68
69
69
/* *
70
- *
71
- * @param index the index
72
- * @return the value at the index
70
+ * @param index The index to search for
71
+ * @return The value at the index
73
72
*/
74
73
auto ValueAt (int index) const -> ValueType;
75
74
76
75
/* *
77
76
* @brief For test only, return a string representing all keys in
78
77
* this internal page, formatted as "(key1,key2,key3,...)"
79
78
*
80
- * @return std:: string
79
+ * @return The string representation of all keys in the current internal page
81
80
*/
82
81
auto ToString () const -> std::string {
83
82
std::string kstr = " (" ;
84
83
bool first = true ;
85
84
86
- // first key of internal page is always invalid
85
+ // First key of internal page is always invalid
87
86
for (int i = 1 ; i < GetSize (); i++) {
88
87
KeyType key = KeyAt (i);
89
88
if (first) {
@@ -103,4 +102,5 @@ class BPlusTreeInternalPage : public BPlusTreePage {
103
102
// Flexible array member for page data.
104
103
MappingType array_[0 ];
105
104
};
105
+
106
106
} // namespace bustub
0 commit comments