Skip to content

Commit

Permalink
split array into two
Browse files Browse the repository at this point in the history
  • Loading branch information
unw9527 committed Sep 26, 2024
1 parent bd0c47c commit b0581b3
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/include/storage/index/index_iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class IndexIterator {

auto IsEnd() -> bool;

auto operator*() -> const MappingType &;
auto operator*() -> std::pair<const KeyType &, const ValueType &>;

auto operator++() -> IndexIterator &;

Expand Down
8 changes: 5 additions & 3 deletions src/include/storage/page/b_plus_tree_internal_page.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
8 changes: 5 additions & 3 deletions src/include/storage/page/b_plus_tree_leaf_page.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
4 changes: 3 additions & 1 deletion src/storage/index/index_iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const KeyType &, const ValueType &> {
throw std::runtime_error("unimplemented");
}

INDEX_TEMPLATE_ARGUMENTS
auto INDEXITERATOR_TYPE::operator++() -> INDEXITERATOR_TYPE & { throw std::runtime_error("unimplemented"); }
Expand Down
12 changes: 4 additions & 8 deletions src/storage/page/b_plus_tree_internal_page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
//===----------------------------------------------------------------------===//

Expand All @@ -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
Expand Down
10 changes: 3 additions & 7 deletions src/storage/page/b_plus_tree_leaf_page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
//===----------------------------------------------------------------------===//

Expand Down Expand Up @@ -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<GenericKey<4>, RID, GenericComparator<4>>;
template class BPlusTreeLeafPage<GenericKey<8>, RID, GenericComparator<8>>;
Expand Down

0 comments on commit b0581b3

Please sign in to comment.