From b0581b35fc0138ccd764596cd8716c2f8d533c0a Mon Sep 17 00:00:00 2001 From: unw9527 <1041593558@qq.com> Date: Thu, 26 Sep 2024 17:29:48 -0400 Subject: [PATCH] split array into two --- src/include/storage/index/index_iterator.h | 2 +- src/include/storage/page/b_plus_tree_internal_page.h | 8 +++++--- src/include/storage/page/b_plus_tree_leaf_page.h | 8 +++++--- src/storage/index/index_iterator.cpp | 4 +++- src/storage/page/b_plus_tree_internal_page.cpp | 12 ++++-------- src/storage/page/b_plus_tree_leaf_page.cpp | 10 +++------- 6 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/include/storage/index/index_iterator.h b/src/include/storage/index/index_iterator.h index 7618823e1..56c04e01e 100644 --- a/src/include/storage/index/index_iterator.h +++ b/src/include/storage/index/index_iterator.h @@ -28,7 +28,7 @@ class IndexIterator { auto IsEnd() -> bool; - auto operator*() -> const MappingType &; + auto operator*() -> std::pair; auto operator++() -> IndexIterator &; 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 29639b98b..54d4fbc4c 100644 --- a/src/include/storage/page/b_plus_tree_internal_page.h +++ b/src/include/storage/page/b_plus_tree_internal_page.h @@ -5,7 +5,7 @@ // // Identification: src/include/page/b_plus_tree_internal_page.h // -// Copyright (c) 2018, Carnegie Mellon University Database Group +// Copyright (c) 2018-2024, Carnegie Mellon University Database Group // //===----------------------------------------------------------------------===// #pragma once @@ -99,8 +99,10 @@ class BPlusTreeInternalPage : public BPlusTreePage { } private: - // Flexible array member for page data. - MappingType array_[0]; + // Flexible array members for page data. + KeyType key_array_[INTERNAL_PAGE_SIZE]; + ValueType value_array_[INTERNAL_PAGE_SIZE]; + // (Fall 2024) Feel free to add more fields and helper functions below if needed }; } // namespace bustub 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 d952647ac..8902687f8 100644 --- a/src/include/storage/page/b_plus_tree_leaf_page.h +++ b/src/include/storage/page/b_plus_tree_leaf_page.h @@ -5,7 +5,7 @@ // // Identification: src/include/page/b_plus_tree_leaf_page.h // -// Copyright (c) 2018, Carnegie Mellon University Database Group +// Copyright (c) 2018-2024, Carnegie Mellon University Database Group // //===----------------------------------------------------------------------===// #pragma once @@ -83,8 +83,10 @@ class BPlusTreeLeafPage : public BPlusTreePage { private: page_id_t next_page_id_; - // Flexible array member for page data. - MappingType array_[0]; + // Flexible array members for page data. + KeyType key_array_[LEAF_PAGE_SIZE]; + ValueType value_array_[LEAF_PAGE_SIZE]; + // (Fall 2024) Feel free to add more fields and helper functions below if needed }; } // namespace bustub diff --git a/src/storage/index/index_iterator.cpp b/src/storage/index/index_iterator.cpp index 3c2ee3ae6..b9ac2b71c 100644 --- a/src/storage/index/index_iterator.cpp +++ b/src/storage/index/index_iterator.cpp @@ -21,7 +21,9 @@ INDEX_TEMPLATE_ARGUMENTS auto INDEXITERATOR_TYPE::IsEnd() -> bool { throw std::runtime_error("unimplemented"); } INDEX_TEMPLATE_ARGUMENTS -auto INDEXITERATOR_TYPE::operator*() -> const MappingType & { throw std::runtime_error("unimplemented"); } +auto INDEXITERATOR_TYPE::operator*() -> std::pair { + throw std::runtime_error("unimplemented"); +} INDEX_TEMPLATE_ARGUMENTS auto INDEXITERATOR_TYPE::operator++() -> INDEXITERATOR_TYPE & { throw std::runtime_error("unimplemented"); } diff --git a/src/storage/page/b_plus_tree_internal_page.cpp b/src/storage/page/b_plus_tree_internal_page.cpp index e0ab2b33c..9be3b0b40 100644 --- a/src/storage/page/b_plus_tree_internal_page.cpp +++ b/src/storage/page/b_plus_tree_internal_page.cpp @@ -5,7 +5,7 @@ // // Identification: src/page/b_plus_tree_internal_page.cpp // -// Copyright (c) 2018, Carnegie Mellon University Database Group +// Copyright (c) 2018-2024, Carnegie Mellon University Database Group // //===----------------------------------------------------------------------===// @@ -26,21 +26,17 @@ namespace bustub { INDEX_TEMPLATE_ARGUMENTS void B_PLUS_TREE_INTERNAL_PAGE_TYPE::Init(int max_size) {} /* - * Helper method to get/set the key associated with input "index"(a.k.a + * Helper method to get/set the key associated with input "index" (a.k.a * array offset) */ INDEX_TEMPLATE_ARGUMENTS -auto B_PLUS_TREE_INTERNAL_PAGE_TYPE::KeyAt(int index) const -> KeyType { - // replace with your own code - KeyType key{}; - return key; -} +auto B_PLUS_TREE_INTERNAL_PAGE_TYPE::KeyAt(int index) const -> KeyType { return {}; } INDEX_TEMPLATE_ARGUMENTS void B_PLUS_TREE_INTERNAL_PAGE_TYPE::SetKeyAt(int index, const KeyType &key) {} /* - * Helper method to get the value associated with input "index"(a.k.a array + * Helper method to get the value associated with input "index" (a.k.a array * offset) */ INDEX_TEMPLATE_ARGUMENTS diff --git a/src/storage/page/b_plus_tree_leaf_page.cpp b/src/storage/page/b_plus_tree_leaf_page.cpp index 3b325d721..763eddb42 100644 --- a/src/storage/page/b_plus_tree_leaf_page.cpp +++ b/src/storage/page/b_plus_tree_leaf_page.cpp @@ -5,7 +5,7 @@ // // Identification: src/page/b_plus_tree_leaf_page.cpp // -// Copyright (c) 2018, Carnegie Mellon University Database Group +// Copyright (c) 2018-2024, Carnegie Mellon University Database Group // //===----------------------------------------------------------------------===// @@ -38,15 +38,11 @@ INDEX_TEMPLATE_ARGUMENTS void B_PLUS_TREE_LEAF_PAGE_TYPE::SetNextPageId(page_id_t next_page_id) {} /* - * Helper method to find and return the key associated with input "index"(a.k.a + * Helper method to find and return the key associated with input "index" (a.k.a * array offset) */ INDEX_TEMPLATE_ARGUMENTS -auto B_PLUS_TREE_LEAF_PAGE_TYPE::KeyAt(int index) const -> KeyType { - // replace with your own code - KeyType key{}; - return key; -} +auto B_PLUS_TREE_LEAF_PAGE_TYPE::KeyAt(int index) const -> KeyType { return {}; } template class BPlusTreeLeafPage, RID, GenericComparator<4>>; template class BPlusTreeLeafPage, RID, GenericComparator<8>>;