diff --git a/src/include/storage/page/b_plus_tree_internal_page.h b/src/include/storage/page/b_plus_tree_internal_page.h index 54d4fbc4c..8dd8ea46a 100644 --- a/src/include/storage/page/b_plus_tree_internal_page.h +++ b/src/include/storage/page/b_plus_tree_internal_page.h @@ -19,7 +19,7 @@ namespace bustub { #define B_PLUS_TREE_INTERNAL_PAGE_TYPE BPlusTreeInternalPage #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. @@ -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 { diff --git a/src/include/storage/page/b_plus_tree_leaf_page.h b/src/include/storage/page/b_plus_tree_leaf_page.h index 8902687f8..0f8e9d217 100644 --- a/src/include/storage/page/b_plus_tree_leaf_page.h +++ b/src/include/storage/page/b_plus_tree_leaf_page.h @@ -20,7 +20,7 @@ namespace bustub { #define B_PLUS_TREE_LEAF_PAGE_TYPE BPlusTreeLeafPage #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, @@ -28,14 +28,23 @@ namespace bustub { * 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 {