Skip to content

Commit

Permalink
Modify header size
Browse files Browse the repository at this point in the history
  • Loading branch information
lanlou1554 committed Sep 28, 2024
1 parent 770d896 commit cd984b0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
14 changes: 10 additions & 4 deletions src/include/storage/page/b_plus_tree_internal_page.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace bustub {

#define B_PLUS_TREE_INTERNAL_PAGE_TYPE BPlusTreeInternalPage<KeyType, ValueType, KeyComparator>
#define INTERNAL_PAGE_HEADER_SIZE 12
#define INTERNAL_PAGE_SIZE ((BUSTUB_PAGE_SIZE - INTERNAL_PAGE_HEADER_SIZE) / (sizeof(MappingType)))
#define INTERNAL_PAGE_SIZE ((BUSTUB_PAGE_SIZE - INTERNAL_PAGE_HEADER_SIZE) / ((int)(sizeof(KeyType) + sizeof(ValueType)))) // NOLINT

/**
* Store `n` indexed keys and `n + 1` child pointers (page_id) within internal page.
Expand All @@ -30,9 +30,15 @@ namespace bustub {
* should ignore the first key.
*
* Internal page format (keys are stored in increasing order):
* ----------------------------------------------------------------------------------
* | HEADER | KEY(1) + PAGE_ID(1) | KEY(2) + PAGE_ID(2) | ... | KEY(n) + PAGE_ID(n) |
* ----------------------------------------------------------------------------------
* ---------
* | HEADER |
* ---------
* ---------------------------------
* | KEY(1) | KEY(2) | ... | KEY(n) |
* ---------------------------------
* ---------------------------------------------
* | PAGE_ID(1) | PAGE_ID(2) | ... | PAGE_ID(n) |
* ---------------------------------------------
*/
INDEX_TEMPLATE_ARGUMENTS
class BPlusTreeInternalPage : public BPlusTreePage {
Expand Down
25 changes: 17 additions & 8 deletions src/include/storage/page/b_plus_tree_leaf_page.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,31 @@ namespace bustub {

#define B_PLUS_TREE_LEAF_PAGE_TYPE BPlusTreeLeafPage<KeyType, ValueType, KeyComparator>
#define LEAF_PAGE_HEADER_SIZE 16
#define LEAF_PAGE_SIZE ((BUSTUB_PAGE_SIZE - LEAF_PAGE_HEADER_SIZE) / sizeof(MappingType))
#define LEAF_PAGE_SIZE ((BUSTUB_PAGE_SIZE - LEAF_PAGE_HEADER_SIZE) / (sizeof(KeyType) + sizeof(ValueType)))

/**
* Store indexed key and record id (record id = page id combined with slot id,
* see `include/common/rid.h` for detailed implementation) together within leaf
* page. Only support unique key.
*
* Leaf page format (keys are stored in order):
* -----------------------------------------------------------------------
* | HEADER | KEY(1) + RID(1) | KEY(2) + RID(2) | ... | KEY(n) + RID(n) |
* -----------------------------------------------------------------------
* ---------
* | HEADER |
* ---------
* ---------------------------------
* | KEY(1) | KEY(2) | ... | KEY(n) |
* ---------------------------------
* ---------------------------------
* | RID(1) | RID(2) | ... | RID(n) |
* ---------------------------------
*
* Header format (size in byte, 16 bytes in total):
* -----------------------------------------------------------------------
* | PageType (4) | CurrentSize (4) | MaxSize (4) | NextPageId (4) | ... |
* -----------------------------------------------------------------------
* Header format (size in byte, 16 bytes in total):
* -----------------------------------------------
* | PageType (4) | CurrentSize (4) | MaxSize (4) |
* -----------------------------------------------
* -----------------
* | NextPageId (4) |
* -----------------
*/
INDEX_TEMPLATE_ARGUMENTS
class BPlusTreeLeafPage : public BPlusTreePage {
Expand Down

0 comments on commit cd984b0

Please sign in to comment.